|
1 | 1 | import libnut = require("@nut-tree/libnut");
|
2 |
| -import { Button } from "../../button.enum"; |
3 |
| -import { Point } from "../../point.class"; |
4 |
| -import { MouseProviderInterface } from "../mouse-provider.interface"; |
| 2 | +import {Button} from "../../button.enum"; |
| 3 | +import {Point} from "../../point.class"; |
| 4 | +import {MouseProviderInterface} from "../mouse-provider.interface"; |
5 | 5 |
|
6 | 6 | export default class MouseAction implements MouseProviderInterface {
|
7 | 7 | public static buttonLookup(btn: Button): any {
|
@@ -41,37 +41,38 @@ export default class MouseAction implements MouseProviderInterface {
|
41 | 41 | }));
|
42 | 42 | }
|
43 | 43 |
|
44 |
| - public leftClick(): Promise<void> { |
| 44 | + public click(btn: Button): Promise<void> { |
45 | 45 | return new Promise<void>(((resolve, reject) => {
|
46 | 46 | try {
|
47 |
| - libnut.mouseClick(MouseAction.buttonLookup(Button.LEFT)); |
| 47 | + libnut.mouseClick(MouseAction.buttonLookup(btn)); |
48 | 48 | resolve();
|
49 | 49 | } catch (e) {
|
50 | 50 | reject(e);
|
51 | 51 | }
|
52 | 52 | }));
|
53 | 53 | }
|
54 | 54 |
|
55 |
| - public rightClick(): Promise<void> { |
| 55 | + public doubleClick(btn: Button): Promise<void> { |
56 | 56 | return new Promise<void>(((resolve, reject) => {
|
57 | 57 | try {
|
58 |
| - libnut.mouseClick(MouseAction.buttonLookup(Button.RIGHT)); |
| 58 | + libnut.mouseClick(MouseAction.buttonLookup(btn), true); |
59 | 59 | resolve();
|
60 | 60 | } catch (e) {
|
61 | 61 | reject(e);
|
62 | 62 | }
|
63 | 63 | }));
|
64 | 64 | }
|
65 | 65 |
|
| 66 | + public leftClick(): Promise<void> { |
| 67 | + return this.click(Button.LEFT); |
| 68 | + } |
| 69 | + |
| 70 | + public rightClick(): Promise<void> { |
| 71 | + return this.click(Button.RIGHT); |
| 72 | + } |
| 73 | + |
66 | 74 | public middleClick(): Promise<void> {
|
67 |
| - return new Promise<void>(((resolve, reject) => { |
68 |
| - try { |
69 |
| - libnut.mouseClick(MouseAction.buttonLookup(Button.MIDDLE)); |
70 |
| - resolve(); |
71 |
| - } catch (e) { |
72 |
| - reject(e); |
73 |
| - } |
74 |
| - })); |
| 75 | + return this.click(Button.MIDDLE); |
75 | 76 | }
|
76 | 77 |
|
77 | 78 | public pressButton(btn: Button): Promise<void> {
|
|
0 commit comments