Skip to content

Instantly share code, notes, and snippets.

@roryok
Last active November 2, 2018 12:40
Show Gist options
  • Save roryok/139c2830beab58867d67 to your computer and use it in GitHub Desktop.
Save roryok/139c2830beab58867d67 to your computer and use it in GitHub Desktop.
an autohotkey script to quickly change mouse sensitivity
;; from http://www.howtogeek.com/howto/45366/how-to-set-different-speeds-for-your-trackpad-and-external-mouse/
#F1::DllCall(“SystemParametersInfo”, Int,113, Int,0, UInt,14, Int,2) ;normal sensisivity
#F2::DllCall(“SystemParametersInfo”, Int,113, Int,0, UInt,6, Int,2) ;low sensitivity
#F3::DllCall(“SystemParametersInfo”, Int,113, Int,0, UInt,20, Int,2) ;high sensitivity
@BucketFreak
Copy link

BucketFreak commented Jul 25, 2018

Hi!

I'm working on a Windows 10 System (64-Bit), using AutoHotKeyU64.
These AHK script lines like DllCall(“SystemParametersInfo”, Int,113, Int,0, UInt,14, Int,2) didn't work for me. At first I was clueless why.

After checking AHK variable ErrorLevel I noticed that the name of the procedure wasn't found by AHK (ErrorLevel = -4).
To correct this I added the following lines to the top of my script:
Global SPIProc, User32Module
User32Module := DllCall("GetModuleHandle", Str, "user32", "Ptr")
SPIProc := DllCall("GetProcAddress", "Ptr", User32Module, "AStr", "SystemParametersInfoW", "Ptr")

Please note that usage of "SystemParametersInfo" instead of "SystemParametersInfoW" didn't work, although the documentation of DllCall() expressively states that an "W" or "A" is added in case the simple name isn't found. Luckily the documentation on the microsoft page Documentation SystemParametersInfo taught me the trick (see very much to the end of the page under "Requirements").

Any call to change mouse sensitivity now looks that way:
DllCall( SPIProc, Int, 0x71, Int, 0, UInt, 5, Int, 0) ; Replace the "5" by your desired sensitivity

Perhaps I'm the only one with this problem, but on the other hand my solution might help somebody,

@roughnecks
Copy link

roughnecks commented Nov 2, 2018

Hello

Can you please post your whole modified script as I'm having the same issue with original code?
Thanks

Edit: It's working like this, hope I did it right

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.

Global SPIProc, User32Module
User32Module := DllCall("GetModuleHandle", Str, "user32", "Ptr")
SPIProc := DllCall("GetProcAddress", "Ptr", User32Module, "AStr", "SystemParametersInfoW", "Ptr")

; Hotkeys are "WIN+F1" and "WIN+F2"

#F1::DllCall( SPIProc, Int, 0x71, Int, 0, UInt, 13, Int, 0) ; Slow: Replace value after "UInt" by your desired sensitivity
#F2::DllCall( SPIProc, Int, 0x71, Int, 0, UInt, 18, Int, 0) ; Fast

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment