@@ -49,32 +49,30 @@ export class KeyboardClass {
49
49
*
50
50
* @param input Sequence of {@link String} or {@link Key} to type
51
51
*/
52
- public type ( ...input : StringOrKey ) : Promise < KeyboardClass > {
53
- return new Promise < KeyboardClass > ( async ( resolve , reject ) => {
54
- try {
55
- if ( inputIsString ( input ) ) {
56
- for ( const char of input . join ( " " ) ) {
57
- await sleep ( this . config . autoDelayMs ) ;
58
- await this . providerRegistry . getKeyboard ( ) . type ( char ) ;
59
- this . providerRegistry . getLogProvider ( ) . debug ( `Tapped ${ char } ` ) ;
60
- }
61
- this . providerRegistry . getLogProvider ( ) . info ( `Typed string ${ input } ` ) ;
62
- } else {
63
- await this . providerRegistry . getKeyboard ( ) . click ( ...( input as Key [ ] ) ) ;
64
- const key = input [ input . length - 1 ] ;
65
- const modifiers = input . slice ( 0 , - 1 ) ;
66
- const keyName = Key [ key ] ;
67
- const modifierNames = modifiers . map ( ( modifier ) => Key [ modifier ] ) ;
68
- this . providerRegistry
69
- . getLogProvider ( )
70
- . info ( `Tapped key ${ keyName } with modifiers ${ modifierNames } ` ) ;
52
+ public async type ( ...input : StringOrKey ) : Promise < KeyboardClass > {
53
+ try {
54
+ if ( inputIsString ( input ) ) {
55
+ for ( const char of input . join ( " " ) ) {
56
+ await sleep ( this . config . autoDelayMs ) ;
57
+ await this . providerRegistry . getKeyboard ( ) . type ( char ) ;
58
+ this . providerRegistry . getLogProvider ( ) . debug ( `Tapped ${ char } ` ) ;
71
59
}
72
- resolve ( this ) ;
73
- } catch ( e ) {
74
- this . providerRegistry . getLogProvider ( ) . error ( e as Error ) ;
75
- reject ( e ) ;
60
+ this . providerRegistry . getLogProvider ( ) . info ( `Typed string ${ input } ` ) ;
61
+ } else {
62
+ await this . providerRegistry . getKeyboard ( ) . click ( ...( input as Key [ ] ) ) ;
63
+ const key = input [ input . length - 1 ] ;
64
+ const modifiers = input . slice ( 0 , - 1 ) ;
65
+ const keyName = Key [ key ] ;
66
+ const modifierNames = modifiers . map ( ( modifier ) => Key [ modifier ] ) ;
67
+ this . providerRegistry
68
+ . getLogProvider ( )
69
+ . info ( `Tapped key ${ keyName } with modifiers ${ modifierNames } ` ) ;
76
70
}
77
- } ) ;
71
+ return this ;
72
+ } catch ( e ) {
73
+ this . providerRegistry . getLogProvider ( ) . error ( e as Error ) ;
74
+ throw e ;
75
+ }
78
76
}
79
77
80
78
/**
@@ -88,19 +86,17 @@ export class KeyboardClass {
88
86
*
89
87
* @param keys Array of {@link Key}s to press and hold
90
88
*/
91
- public pressKey ( ...keys : Key [ ] ) : Promise < KeyboardClass > {
92
- return new Promise < KeyboardClass > ( async ( resolve , reject ) => {
93
- try {
94
- await sleep ( this . config . autoDelayMs ) ;
95
- await this . providerRegistry . getKeyboard ( ) . pressKey ( ...keys ) ;
96
- const keyNames = keys . map ( ( key ) => Key [ key ] ) ;
97
- this . providerRegistry . getLogProvider ( ) . info ( `Pressed keys ${ keyNames } ` ) ;
98
- resolve ( this ) ;
99
- } catch ( e ) {
100
- this . providerRegistry . getLogProvider ( ) . error ( e as Error ) ;
101
- reject ( e ) ;
102
- }
103
- } ) ;
89
+ public async pressKey ( ...keys : Key [ ] ) : Promise < KeyboardClass > {
90
+ try {
91
+ await sleep ( this . config . autoDelayMs ) ;
92
+ await this . providerRegistry . getKeyboard ( ) . pressKey ( ...keys ) ;
93
+ const keyNames = keys . map ( ( key ) => Key [ key ] ) ;
94
+ this . providerRegistry . getLogProvider ( ) . info ( `Pressed keys ${ keyNames } ` ) ;
95
+ return this ;
96
+ } catch ( e ) {
97
+ this . providerRegistry . getLogProvider ( ) . error ( e as Error ) ;
98
+ throw e ;
99
+ }
104
100
}
105
101
106
102
/**
@@ -114,20 +110,16 @@ export class KeyboardClass {
114
110
*
115
111
* @param keys Array of {@link Key}s to release
116
112
*/
117
- public releaseKey ( ...keys : Key [ ] ) : Promise < KeyboardClass > {
118
- return new Promise < KeyboardClass > ( async ( resolve , reject ) => {
119
- try {
120
- await sleep ( this . config . autoDelayMs ) ;
121
- await this . providerRegistry . getKeyboard ( ) . releaseKey ( ...keys ) ;
122
- const keyNames = keys . map ( ( key ) => Key [ key ] ) ;
123
- this . providerRegistry
124
- . getLogProvider ( )
125
- . info ( `Released keys ${ keyNames } ` ) ;
126
- resolve ( this ) ;
127
- } catch ( e ) {
128
- this . providerRegistry . getLogProvider ( ) . error ( e as Error ) ;
129
- reject ( e ) ;
130
- }
131
- } ) ;
113
+ public async releaseKey ( ...keys : Key [ ] ) : Promise < KeyboardClass > {
114
+ try {
115
+ await sleep ( this . config . autoDelayMs ) ;
116
+ await this . providerRegistry . getKeyboard ( ) . releaseKey ( ...keys ) ;
117
+ const keyNames = keys . map ( ( key ) => Key [ key ] ) ;
118
+ this . providerRegistry . getLogProvider ( ) . info ( `Released keys ${ keyNames } ` ) ;
119
+ return this ;
120
+ } catch ( e ) {
121
+ this . providerRegistry . getLogProvider ( ) . error ( e as Error ) ;
122
+ throw e ;
123
+ }
132
124
}
133
125
}
0 commit comments