File tree 1 file changed +27
-15
lines changed
1 file changed +27
-15
lines changed Original file line number Diff line number Diff line change @@ -21,31 +21,43 @@ export class Keyboard {
21
21
}
22
22
23
23
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 [ ] ) ;
30
34
}
31
- } else {
32
- await this . nativeAdapter . click ( ...input as Key [ ] ) ;
35
+ resolve ( this ) ;
36
+ } catch ( e ) {
37
+ reject ( e ) ;
33
38
}
34
- resolve ( this ) ;
35
39
} ) ;
36
40
}
37
41
38
42
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
+ }
42
50
} ) ;
43
51
}
44
52
45
53
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
+ }
49
61
} ) ;
50
62
}
51
63
You can’t perform that action at this time.
0 commit comments