11import { NativeAdapter } from "./adapter/native.adapter.class" ;
22import { Key } from "./key.enum" ;
33
4- export class Keyboard {
4+ type StringOrKey = string [ ] | Key [ ] ;
55
6- private static inputIsString ( input : string [ ] | Key [ ] ) : boolean {
7- return input . every ( ( elem : string | Key ) => typeof elem === "string" ) ;
8- }
6+ const inputIsString = ( input : string [ ] | Key [ ] ) : input is string [ ] => {
7+ return input . every ( ( elem : string | Key ) => typeof elem === "string" ) ;
8+ } ;
9+
10+ export class Keyboard {
911
1012 public config = {
1113 autoDelayMs : 500 ,
@@ -18,11 +20,11 @@ export class Keyboard {
1820 this . lastAction = Date . now ( ) ;
1921 }
2022
21- public type ( ...input : string [ ] | Key [ ] ) : Promise < Keyboard > {
23+ public type ( ...input : StringOrKey ) : Promise < Keyboard > {
2224 return new Promise < Keyboard > ( async resolve => {
23- if ( Keyboard . inputIsString ( input ) ) {
25+ if ( inputIsString ( input ) ) {
2426 for ( const char of input . join ( " " ) . split ( "" ) ) {
25- await this . waitForNextTick ( ) ;
27+ await this . nextTick ( ) ;
2628 this . nativeAdapter . type ( char ) ;
2729 this . updateTick ( ) ;
2830 }
@@ -51,7 +53,7 @@ export class Keyboard {
5153 this . lastAction = Date . now ( ) ;
5254 }
5355
54- private async waitForNextTick ( ) : Promise < void > {
56+ private async nextTick ( ) : Promise < void > {
5557 return new Promise < void > ( resolve => {
5658 let current = Date . now ( ) ;
5759 while ( current - this . lastAction < this . config . autoDelayMs ) {
0 commit comments