Skip to content
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

fix: Tune windows: scroll API #231

Merged
merged 1 commit into from
Dec 11, 2023
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
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,9 @@ interClickDelayMs | number | no | Duration of the pause between each click gestu

### windows: scroll

This is a shortcut for a mouse wheel scroll gesture.
This is a shortcut for a mouse wheel scroll gesture. The API is a thin wrapper over the [SendInput](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendinput#:~:text=The%20SendInput%20function%20inserts%20the,or%20other%20calls%20to%20SendInput.)
WinApi call. It emulates the mouse cursor movement and/or horizontal/vertical rotation of the mouse wheel.
Thus make sure the target control is ready to receive mouse wheel events (e.g. is focused) before invoking it.

#### Arguments

Expand All @@ -297,8 +299,8 @@ Name | Type | Required | Description | Example
elementId | string | no | Same as in [windows: click](#windows-click) | 123e4567-e89b-12d3-a456-426614174000
x | number | no | Same as in [windows: click](#windows-click) | 100
y | number | no | Same as in [windows: click](#windows-click) | 100
deltaX | number | no | The amount of horizontal wheel movement. A positive value indicates that the wheel was rotated to the right; a negative value indicates that the wheel was rotated to the left. Either this value or deltaY must be provided, but not both. | -100
deltaY | number | no | The amount of vertical wheel movement. A positive value indicates that the wheel was rotated forward, away from the user; a negative value indicates that the wheel was rotated backward, toward the user. Either this value or deltaX must be provided, but not both. | 100
deltaX | number | no | The amount of horizontal wheel movement measured in wheel clicks. A positive value indicates that the wheel was rotated to the right; a negative value indicates that the wheel was rotated to the left. Either this value or deltaY must be provided, but not both. | -5
deltaY | number | no | The amount of vertical wheel movement measured in wheel clicks. A positive value indicates that the wheel was rotated forward, away from the user; a negative value indicates that the wheel was rotated backward, toward the user. Either this value or deltaX must be provided, but not both. | 5
modifierKeys | string[] or string | no | Same as in [windows: click](#windows-click) | win

### windows: clickAndDrag
Expand Down
5 changes: 3 additions & 2 deletions lib/commands/winapi/user32.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ const XBUTTON2 = 0x0002;
const SM_CXVIRTUALSCREEN = 78;
const SM_CYVIRTUALSCREEN = 79;
const MOUSE_MOVE_NORM = 0xFFFF;
const WHEEL_DELTA = 120;


export function createKeyInput(params = {}) {
Expand Down Expand Up @@ -377,13 +378,13 @@ export function toMouseWheelInput({dx, dy}) {
// According to MSDN, MOUSEEVENTF_HWHELL and MOUSEEVENTF_WHEEL are both
// required for a horizontal wheel event.
return createMouseInput({
mouseData: dx,
mouseData: dx * WHEEL_DELTA,
dwFlags: MOUSEEVENTF_HWHEEL | MOUSEEVENTF_WHEEL,
});
}
if (hasVerticalScroll && dy !== 0) {
return createMouseInput({
mouseData: dy,
mouseData: dy * WHEEL_DELTA,
dwFlags: MOUSEEVENTF_WHEEL,
});
}
Expand Down