Skip to content

Commit 5647eaf

Browse files
committed
WIP: Adding support for mouse wheel events
1 parent bed0a56 commit 5647eaf

File tree

5 files changed

+27
-2
lines changed

5 files changed

+27
-2
lines changed

components/assistive-playwright-client/src/vm/mouse.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ export class VMMouse implements Mouse {
5757
public calibration: CalibrationResult
5858
) {}
5959

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

6464
/**

components/assistive-webdriver/test/helpers/vmMock.ts

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export interface VMMock extends VM {
5050
sendMouseMoveEvent: AsyncFnMock<void, [ScreenPosition]>;
5151
sendMouseDownEvent: AsyncFnMock<void, [MouseButton]>;
5252
sendMouseUpEvent: AsyncFnMock<void, [MouseButton]>;
53+
sendMouseWheelEvent: AsyncFnMock<void, [number, number]>;
5354
takePNGScreenshot: AsyncFnMock<import("pngjs").PNG, []>;
5455
}
5556

@@ -64,5 +65,6 @@ export const createVMMock = (
6465
sendMouseDownEvent: asyncFnMock(`${vmName}.sendMouseDownEvent`),
6566
sendMouseMoveEvent: asyncFnMock(`${vmName}.sendMouseMoveEvent`),
6667
sendMouseUpEvent: asyncFnMock(`${vmName}.sendMouseUpEvent`),
68+
sendMouseWheelEvent: asyncFnMock(`${vmName}.sendMouseWheelEvent`),
6769
takePNGScreenshot: asyncFnMock(`${vmName}.takePNGScreenshot`)
6870
});

components/vm-providers/src/vm/qemu/qemu.ts

+5
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,11 @@ export class QEMUVM implements VM {
282282
});
283283
}
284284

285+
async sendMouseWheelEvent(deltaX: number, deltaY: number): Promise<void> {
286+
// TODO: implement this
287+
throw new Error("Method not implemented.");
288+
}
289+
285290
async sendMouseDownEvent(button: MouseButton): Promise<void> {
286291
await this._sendCommand({
287292
execute: "input-send-event",

components/vm-providers/src/vm/virtualbox/vm.ts

+11
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,17 @@ export class VirtualboxVM implements VM {
209209
await this.vboxMouse!.putMouseEvent(0, 0, 0, 0, this.vboxMouseButtonState);
210210
}
211211

212+
async sendMouseWheelEvent(deltaX: number, deltaY: number): Promise<void> {
213+
// TODO: check if it works correctly
214+
await this.vboxMouse!.putMouseEvent(
215+
0,
216+
0,
217+
deltaY,
218+
deltaX,
219+
this.vboxMouseButtonState
220+
);
221+
}
222+
212223
async takePNGScreenshot(): Promise<PNG> {
213224
const resolution = await this.vboxDisplay!.getScreenResolution(0);
214225
const screenshot = await this.vboxDisplay!.takeScreenShotToArray(

components/vm-providers/src/vm/vmInterface.ts

+7
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ export interface VM {
142142
*/
143143
sendMouseUpEvent(button: MouseButton): Promise<void>;
144144

145+
/**
146+
* Sends a mouse wheel event to the virtual machine.
147+
* @param deltaX - amount to scroll horizontally
148+
* @param deltaY - amount to scroll vertically
149+
*/
150+
sendMouseWheelEvent(deltaX: number, deltaY: number): Promise<void>;
151+
145152
/**
146153
* Takes a screenshot of the virtual machine and returns the corresponding PNG image.
147154
*/

0 commit comments

Comments
 (0)