Skip to content

Commit

Permalink
Disable mouse acceleration on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
pentamassiv committed Aug 13, 2024
1 parent 76d1062 commit 8a4e455
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,25 @@ jobs:
if: runner.os == 'Linux' # This step is only needed on Linux. The other OSs don't need to be set up
uses: ./.github/actions/headless_display

- name: Check Mouse Acceleration
run: |
reg query "HKEY_CURRENT_USER\Control Panel\Mouse" /v MouseSpeed
reg query "HKEY_CURRENT_USER\Control Panel\Mouse" /v MouseThreshold1
reg query "HKEY_CURRENT_USER\Control Panel\Mouse" /v MouseThreshold2
shell: powershell
- name: Disable Mouse Acceleration
run: |
reg add "HKEY_CURRENT_USER\Control Panel\Mouse" /v MouseSpeed /t REG_SZ /d 0 /f
reg add "HKEY_CURRENT_USER\Control Panel\Mouse" /v MouseThreshold1 /t REG_SZ /d 0 /f
reg add "HKEY_CURRENT_USER\Control Panel\Mouse" /v MouseThreshold2 /t REG_SZ /d 0 /f
shell: powershell
- name: Verify Mouse Acceleration is Disabled
run: |
reg query "HKEY_CURRENT_USER\Control Panel\Mouse" /v MouseSpeed
reg query "HKEY_CURRENT_USER\Control Panel\Mouse" /v MouseThreshold1
reg query "HKEY_CURRENT_USER\Control Panel\Mouse" /v MouseThreshold2
shell: powershell

- name: Run the unit tests
run: cargo test unit --no-default-features --features ${{ matrix.features }} -- --test-threads=1 --nocapture

Expand Down
13 changes: 1 addition & 12 deletions src/win/win_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,7 @@ impl Mouse for Enigo {
let y = (y * 65535 + h / 2 * y.signum()) / h;
(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, x as i32, y as i32)
} else {
// 0-screen width/height - 1 map to 0-65535
// Add w/2 or h/2 to round off
// See https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-mouse_event#remarks
let (w, h) = self.main_display()?;
let w = w as i64 - 1;
let h = h as i64 - 1;
let x = x as i64;
let y = y as i64;
let x = (x * 65535 + w / 2 * x.signum()) * w;
let y = (y * 65535 + h / 2 * y.signum()) * h;

(MOUSEEVENTF_MOVE, x as i32, y as i32)
(MOUSEEVENTF_MOVE, x, y)
};
let input = mouse_event(flags, 0, x, y, self.dw_extra_info);
send_input(&[input])
Expand Down

0 comments on commit 8a4e455

Please sign in to comment.