Skip to content

Commit

Permalink
WIP: Adding support for mouse wheel events
Browse files Browse the repository at this point in the history
  • Loading branch information
divdavem committed Sep 23, 2021
1 parent bed0a56 commit 5647eaf
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions components/assistive-playwright-client/src/vm/mouse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export class VMMouse implements Mouse {
public calibration: CalibrationResult
) {}

wheel(deltaX: number, deltaY: number): Promise<void> {
throw new Error("Method not implemented yet.");
async wheel(deltaX: number, deltaY: number): Promise<void> {
await this.vm.sendMouseWheelEvent(deltaX, deltaY);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions components/assistive-webdriver/test/helpers/vmMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface VMMock extends VM {
sendMouseMoveEvent: AsyncFnMock<void, [ScreenPosition]>;
sendMouseDownEvent: AsyncFnMock<void, [MouseButton]>;
sendMouseUpEvent: AsyncFnMock<void, [MouseButton]>;
sendMouseWheelEvent: AsyncFnMock<void, [number, number]>;
takePNGScreenshot: AsyncFnMock<import("pngjs").PNG, []>;
}

Expand All @@ -64,5 +65,6 @@ export const createVMMock = (
sendMouseDownEvent: asyncFnMock(`${vmName}.sendMouseDownEvent`),
sendMouseMoveEvent: asyncFnMock(`${vmName}.sendMouseMoveEvent`),
sendMouseUpEvent: asyncFnMock(`${vmName}.sendMouseUpEvent`),
sendMouseWheelEvent: asyncFnMock(`${vmName}.sendMouseWheelEvent`),
takePNGScreenshot: asyncFnMock(`${vmName}.takePNGScreenshot`)
});
5 changes: 5 additions & 0 deletions components/vm-providers/src/vm/qemu/qemu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,11 @@ export class QEMUVM implements VM {
});
}

async sendMouseWheelEvent(deltaX: number, deltaY: number): Promise<void> {
// TODO: implement this
throw new Error("Method not implemented.");
}

async sendMouseDownEvent(button: MouseButton): Promise<void> {
await this._sendCommand({
execute: "input-send-event",
Expand Down
11 changes: 11 additions & 0 deletions components/vm-providers/src/vm/virtualbox/vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,17 @@ export class VirtualboxVM implements VM {
await this.vboxMouse!.putMouseEvent(0, 0, 0, 0, this.vboxMouseButtonState);
}

async sendMouseWheelEvent(deltaX: number, deltaY: number): Promise<void> {
// TODO: check if it works correctly
await this.vboxMouse!.putMouseEvent(
0,
0,
deltaY,
deltaX,
this.vboxMouseButtonState
);
}

async takePNGScreenshot(): Promise<PNG> {
const resolution = await this.vboxDisplay!.getScreenResolution(0);
const screenshot = await this.vboxDisplay!.takeScreenShotToArray(
Expand Down
7 changes: 7 additions & 0 deletions components/vm-providers/src/vm/vmInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ export interface VM {
*/
sendMouseUpEvent(button: MouseButton): Promise<void>;

/**
* Sends a mouse wheel event to the virtual machine.
* @param deltaX - amount to scroll horizontally
* @param deltaY - amount to scroll vertically
*/
sendMouseWheelEvent(deltaX: number, deltaY: number): Promise<void>;

/**
* Takes a screenshot of the virtual machine and returns the corresponding PNG image.
*/
Expand Down

0 comments on commit 5647eaf

Please sign in to comment.