@@ -12,54 +12,131 @@ export class MouseAction implements MouseActionInterface {
1212 [ [ Button . LEFT , "left" ] , [ Button . MIDDLE , "middle" ] , [ Button . RIGHT , "right" ] ] ,
1313 ) ;
1414
15- constructor ( ) { }
15+ constructor ( ) {
16+ }
1617
1718 public setMouseDelay ( delay : number ) : void {
1819 robot . setMouseDelay ( delay ) ;
1920 }
2021
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+ } ) ) ;
2331 }
2432
2533 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+ } ) ) ;
2842 }
2943
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+ } ) ) ;
3253 }
3354
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+ } ) ) ;
3664 }
3765
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+ } ) ) ;
4075 }
4176
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+ } ) ) ;
4486 }
4587
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+ } ) ) ;
4897 }
4998
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+ } ) ) ;
52108 }
53109
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+ } ) ) ;
56119 }
57120
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+ } ) ) ;
60130 }
61131
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+ } ) ) ;
64141 }
65142}
0 commit comments