@@ -12,54 +12,131 @@ export class MouseAction implements MouseActionInterface {
12
12
[ [ Button . LEFT , "left" ] , [ Button . MIDDLE , "middle" ] , [ Button . RIGHT , "right" ] ] ,
13
13
) ;
14
14
15
- constructor ( ) { }
15
+ constructor ( ) {
16
+ }
16
17
17
18
public setMouseDelay ( delay : number ) : void {
18
19
robot . setMouseDelay ( delay ) ;
19
20
}
20
21
21
- public setMousePosition ( p : Point ) : void {
22
- robot . moveMouse ( p . x , p . y ) ;
22
+ public setMousePosition ( p : Point ) : Promise < void > {
23
+ return new Promise < void > ( ( ( resolve , reject ) => {
24
+ try {
25
+ robot . moveMouse ( p . x , p . y ) ;
26
+ resolve ( ) ;
27
+ } catch ( e ) {
28
+ reject ( e ) ;
29
+ }
30
+ } ) ) ;
23
31
}
24
32
25
33
public currentMousePosition ( ) : Promise < Point > {
26
- const position = robot . getMousePos ( ) ;
27
- return Promise . resolve ( new Point ( position . x , position . y ) ) ;
34
+ return new Promise < Point > ( ( ( resolve , reject ) => {
35
+ try {
36
+ const position = robot . getMousePos ( ) ;
37
+ resolve ( new Point ( position . x , position . y ) ) ;
38
+ } catch ( e ) {
39
+ reject ( e ) ;
40
+ }
41
+ } ) ) ;
28
42
}
29
43
30
- public leftClick ( ) : void {
31
- robot . mouseClick ( MouseAction . buttonLookup ( Button . LEFT ) ) ;
44
+ public leftClick ( ) : Promise < void > {
45
+ return new Promise < void > ( ( ( resolve , reject ) => {
46
+ try {
47
+ robot . mouseClick ( MouseAction . buttonLookup ( Button . LEFT ) ) ;
48
+ resolve ( ) ;
49
+ } catch ( e ) {
50
+ reject ( e ) ;
51
+ }
52
+ } ) ) ;
32
53
}
33
54
34
- public rightClick ( ) : void {
35
- robot . mouseClick ( MouseAction . buttonLookup ( Button . RIGHT ) ) ;
55
+ public rightClick ( ) : Promise < void > {
56
+ return new Promise < void > ( ( ( resolve , reject ) => {
57
+ try {
58
+ robot . mouseClick ( MouseAction . buttonLookup ( Button . RIGHT ) ) ;
59
+ resolve ( ) ;
60
+ } catch ( e ) {
61
+ reject ( e ) ;
62
+ }
63
+ } ) ) ;
36
64
}
37
65
38
- public middleClick ( ) : void {
39
- robot . mouseClick ( MouseAction . buttonLookup ( Button . MIDDLE ) ) ;
66
+ public middleClick ( ) : Promise < void > {
67
+ return new Promise < void > ( ( ( resolve , reject ) => {
68
+ try {
69
+ robot . mouseClick ( MouseAction . buttonLookup ( Button . MIDDLE ) ) ;
70
+ resolve ( ) ;
71
+ } catch ( e ) {
72
+ reject ( e ) ;
73
+ }
74
+ } ) ) ;
40
75
}
41
76
42
- public pressButton ( btn : Button ) : void {
43
- robot . mouseToggle ( "down" , MouseAction . buttonLookup ( btn ) ) ;
77
+ public pressButton ( btn : Button ) : Promise < void > {
78
+ return new Promise < void > ( ( ( resolve , reject ) => {
79
+ try {
80
+ robot . mouseToggle ( "down" , MouseAction . buttonLookup ( btn ) ) ;
81
+ resolve ( ) ;
82
+ } catch ( e ) {
83
+ reject ( e ) ;
84
+ }
85
+ } ) ) ;
44
86
}
45
87
46
- public releaseButton ( btn : Button ) : void {
47
- robot . mouseToggle ( "up" , MouseAction . buttonLookup ( btn ) ) ;
88
+ public releaseButton ( btn : Button ) : Promise < void > {
89
+ return new Promise < void > ( ( ( resolve , reject ) => {
90
+ try {
91
+ robot . mouseToggle ( "up" , MouseAction . buttonLookup ( btn ) ) ;
92
+ resolve ( ) ;
93
+ } catch ( e ) {
94
+ reject ( e ) ;
95
+ }
96
+ } ) ) ;
48
97
}
49
98
50
- public scrollUp ( amount : number ) : void {
51
- robot . scrollMouse ( 0 , amount ) ;
99
+ public scrollUp ( amount : number ) : Promise < void > {
100
+ return new Promise < void > ( ( ( resolve , reject ) => {
101
+ try {
102
+ robot . scrollMouse ( 0 , amount ) ;
103
+ resolve ( ) ;
104
+ } catch ( e ) {
105
+ reject ( e ) ;
106
+ }
107
+ } ) ) ;
52
108
}
53
109
54
- public scrollDown ( amount : number ) : void {
55
- robot . scrollMouse ( 0 , - amount ) ;
110
+ public scrollDown ( amount : number ) : Promise < void > {
111
+ return new Promise < void > ( ( ( resolve , reject ) => {
112
+ try {
113
+ robot . scrollMouse ( 0 , - amount ) ;
114
+ resolve ( ) ;
115
+ } catch ( e ) {
116
+ reject ( e ) ;
117
+ }
118
+ } ) ) ;
56
119
}
57
120
58
- public scrollLeft ( amount : number ) : void {
59
- robot . scrollMouse ( - amount , 0 ) ;
121
+ public scrollLeft ( amount : number ) : Promise < void > {
122
+ return new Promise < void > ( ( ( resolve , reject ) => {
123
+ try {
124
+ robot . scrollMouse ( - amount , 0 ) ;
125
+ resolve ( ) ;
126
+ } catch ( e ) {
127
+ reject ( e ) ;
128
+ }
129
+ } ) ) ;
60
130
}
61
131
62
- public scrollRight ( amount : number ) : void {
63
- robot . scrollMouse ( amount , 0 ) ;
132
+ public scrollRight ( amount : number ) : Promise < void > {
133
+ return new Promise < void > ( ( ( resolve , reject ) => {
134
+ try {
135
+ robot . scrollMouse ( amount , 0 ) ;
136
+ resolve ( ) ;
137
+ } catch ( e ) {
138
+ reject ( e ) ;
139
+ }
140
+ } ) ) ;
64
141
}
65
142
}
0 commit comments