@@ -129,41 +129,76 @@ export class KeyboardAction implements KeyboardActionProvider {
129
129
. filter ( modifierKey => modifierKey != null && modifierKey . length > 1 ) ;
130
130
}
131
131
132
- private static key ( key : Key , event : "up" | "down" , ...modifiers : Key [ ] ) {
133
- const nativeKey = KeyboardAction . keyLookup ( key ) ;
134
- const modifierKeys = this . mapModifierKeys ( ...modifiers ) ;
135
- if ( nativeKey ) {
136
- robot . keyToggle ( nativeKey , event , modifierKeys ) ;
137
- }
132
+ private static key ( key : Key , event : "up" | "down" , ...modifiers : Key [ ] ) : Promise < void > {
133
+ return new Promise < void > ( ( resolve , reject ) => {
134
+ try {
135
+ const nativeKey = KeyboardAction . keyLookup ( key ) ;
136
+ const modifierKeys = this . mapModifierKeys ( ...modifiers ) ;
137
+ if ( nativeKey ) {
138
+ robot . keyToggle ( nativeKey , event , modifierKeys ) ;
139
+ }
140
+ resolve ( ) ;
141
+ } catch ( e ) {
142
+ reject ( e ) ;
143
+ }
144
+ } ) ;
138
145
}
139
146
140
147
constructor ( ) {
141
148
}
142
149
143
- public type ( input : string ) : void {
144
- robot . typeString ( input ) ;
150
+ public type ( input : string ) : Promise < void > {
151
+ return new Promise < void > ( ( ( resolve , reject ) => {
152
+ try {
153
+ robot . typeString ( input ) ;
154
+ resolve ( ) ;
155
+ } catch ( e ) {
156
+ reject ( e ) ;
157
+ }
158
+ } ) ) ;
145
159
}
146
160
147
- public click ( ...keys : Key [ ] ) : void {
148
- keys . reverse ( ) ;
149
- const [ key , ...modifiers ] = keys ;
150
- const nativeKey = KeyboardAction . keyLookup ( key ) ;
151
- const modifierKeys = KeyboardAction . mapModifierKeys ( ...modifiers ) ;
152
- if ( nativeKey ) {
153
- robot . keyTap ( nativeKey , modifierKeys ) ;
154
- }
161
+ public click ( ...keys : Key [ ] ) : Promise < void > {
162
+ return new Promise < void > ( ( ( resolve , reject ) => {
163
+ try {
164
+ keys . reverse ( ) ;
165
+ const [ key , ...modifiers ] = keys ;
166
+ const nativeKey = KeyboardAction . keyLookup ( key ) ;
167
+ const modifierKeys = KeyboardAction . mapModifierKeys ( ...modifiers ) ;
168
+ if ( nativeKey ) {
169
+ robot . keyTap ( nativeKey , modifierKeys ) ;
170
+ }
171
+ resolve ( ) ;
172
+ } catch ( e ) {
173
+ reject ( e ) ;
174
+ }
175
+ } ) ) ;
155
176
}
156
177
157
- public pressKey ( ...keys : Key [ ] ) : void {
158
- keys . reverse ( ) ;
159
- const [ key , ...modifiers ] = keys ;
160
- KeyboardAction . key ( key , "down" , ...modifiers ) ;
178
+ public pressKey ( ...keys : Key [ ] ) : Promise < void > {
179
+ return new Promise < void > ( ( ( resolve , reject ) => {
180
+ try {
181
+ keys . reverse ( ) ;
182
+ const [ key , ...modifiers ] = keys ;
183
+ KeyboardAction . key ( key , "down" , ...modifiers ) ;
184
+ resolve ( ) ;
185
+ } catch ( e ) {
186
+ reject ( e ) ;
187
+ }
188
+ } ) ) ;
161
189
}
162
190
163
- public releaseKey ( ...keys : Key [ ] ) : void {
164
- keys . reverse ( ) ;
165
- const [ key , ...modifiers ] = keys ;
166
- KeyboardAction . key ( key , "up" , ...modifiers ) ;
191
+ public releaseKey ( ...keys : Key [ ] ) : Promise < void > {
192
+ return new Promise < void > ( ( ( resolve , reject ) => {
193
+ try {
194
+ keys . reverse ( ) ;
195
+ const [ key , ...modifiers ] = keys ;
196
+ KeyboardAction . key ( key , "up" , ...modifiers ) ;
197
+ resolve ( ) ;
198
+ } catch ( e ) {
199
+ reject ( e ) ;
200
+ }
201
+ } ) ) ;
167
202
}
168
203
169
204
public setKeyboardDelay ( delay : number ) : void {
0 commit comments