File tree Expand file tree Collapse file tree 1 file changed +27
-15
lines changed Expand file tree Collapse file tree 1 file changed +27
-15
lines changed Original file line number Diff line number Diff line change @@ -21,31 +21,43 @@ export class Keyboard {
2121 }
2222
2323 public type ( ...input : StringOrKey ) : Promise < Keyboard > {
24- return new Promise < Keyboard > ( async resolve => {
25- if ( inputIsString ( input ) ) {
26- for ( const char of input . join ( " " ) . split ( "" ) ) {
27- await this . nextTick ( ) ;
28- await this . nativeAdapter . type ( char ) ;
29- this . updateTick ( ) ;
24+ return new Promise < Keyboard > ( async ( resolve , reject ) => {
25+ try {
26+ if ( inputIsString ( input ) ) {
27+ for ( const char of input . join ( " " ) . split ( "" ) ) {
28+ await this . nextTick ( ) ;
29+ await this . nativeAdapter . type ( char ) ;
30+ this . updateTick ( ) ;
31+ }
32+ } else {
33+ await this . nativeAdapter . click ( ...input as Key [ ] ) ;
3034 }
31- } else {
32- await this . nativeAdapter . click ( ...input as Key [ ] ) ;
35+ resolve ( this ) ;
36+ } catch ( e ) {
37+ reject ( e ) ;
3338 }
34- resolve ( this ) ;
3539 } ) ;
3640 }
3741
3842 public pressKey ( ...keys : Key [ ] ) : Promise < Keyboard > {
39- return new Promise < Keyboard > ( async resolve => {
40- await this . nativeAdapter . pressKey ( ...keys ) ;
41- resolve ( this ) ;
43+ return new Promise < Keyboard > ( async ( resolve , reject ) => {
44+ try {
45+ await this . nativeAdapter . pressKey ( ...keys ) ;
46+ resolve ( this ) ;
47+ } catch ( e ) {
48+ reject ( e ) ;
49+ }
4250 } ) ;
4351 }
4452
4553 public releaseKey ( ...keys : Key [ ] ) : Promise < Keyboard > {
46- return new Promise < Keyboard > ( async resolve => {
47- await this . nativeAdapter . releaseKey ( ...keys ) ;
48- resolve ( this ) ;
54+ return new Promise < Keyboard > ( async ( resolve , reject ) => {
55+ try {
56+ await this . nativeAdapter . releaseKey ( ...keys ) ;
57+ resolve ( this ) ;
58+ } catch ( e ) {
59+ reject ( e ) ;
60+ }
4961 } ) ;
5062 }
5163
You can’t perform that action at this time.
0 commit comments