Skip to content

Feature/373/macos doubleclick #389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions lib/mouse.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,34 @@ export class MouseClass {
}
});
}

/**
* {@link click} clicks a mouse button
* @param btn The {@link Button} to click
*/
public async click(btn: Button): Promise<MouseClass> {
return new Promise<MouseClass>(async (resolve, reject) => {
try {
await this.providerRegistry.getMouse().click(btn);
resolve(this);
} catch (e) {
reject(e);
}
});
}

/**
* {@link doubleClick} performs a double click on a mouse button
* @param btn The {@link Button} to click
*/
public async doubleClick(btn: Button): Promise<MouseClass> {
return new Promise<MouseClass>(async (resolve, reject) => {
try {
await this.providerRegistry.getMouse().doubleClick(btn);
resolve(this);
} catch (e) {
reject(e);
}
});
}
}
14 changes: 14 additions & 0 deletions lib/provider/mouse-provider.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ export interface MouseProviderInterface {
*/
currentMousePosition(): Promise<Point>;

/**
* click should allow to perform a single click via OS event
*
* @param btn The {@link Button} to click
*/
click(btn: Button): Promise<void>;

/**
* doubleClick should allow to perform a double click via OS event
*
* @param btn The {@link Button} to click
*/
doubleClick(btn: Button): Promise<void>;

/**
* leftClick should allow to perform a left click via OS event
*/
Expand Down
31 changes: 16 additions & 15 deletions lib/provider/native/libnut-mouse.class.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import libnut = require("@nut-tree/libnut");
import { Button } from "../../button.enum";
import { Point } from "../../point.class";
import { MouseProviderInterface } from "../mouse-provider.interface";
import {Button} from "../../button.enum";
import {Point} from "../../point.class";
import {MouseProviderInterface} from "../mouse-provider.interface";

export default class MouseAction implements MouseProviderInterface {
public static buttonLookup(btn: Button): any {
Expand Down Expand Up @@ -41,37 +41,38 @@ export default class MouseAction implements MouseProviderInterface {
}));
}

public leftClick(): Promise<void> {
public click(btn: Button): Promise<void> {
return new Promise<void>(((resolve, reject) => {
try {
libnut.mouseClick(MouseAction.buttonLookup(Button.LEFT));
libnut.mouseClick(MouseAction.buttonLookup(btn));
resolve();
} catch (e) {
reject(e);
}
}));
}

public rightClick(): Promise<void> {
public doubleClick(btn: Button): Promise<void> {
return new Promise<void>(((resolve, reject) => {
try {
libnut.mouseClick(MouseAction.buttonLookup(Button.RIGHT));
libnut.mouseClick(MouseAction.buttonLookup(btn), true);
resolve();
} catch (e) {
reject(e);
}
}));
}

public leftClick(): Promise<void> {
return this.click(Button.LEFT);
}

public rightClick(): Promise<void> {
return this.click(Button.RIGHT);
}

public middleClick(): Promise<void> {
return new Promise<void>(((resolve, reject) => {
try {
libnut.mouseClick(MouseAction.buttonLookup(Button.MIDDLE));
resolve();
} catch (e) {
reject(e);
}
}));
return this.click(Button.MIDDLE);
}

public pressButton(btn: Button): Promise<void> {
Expand Down