Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Adjusting Mouse Sensitivity via hotkey


  • Please log in to reply
19 replies to this topic
Esoteria
  • Guests
  • Last active:
  • Joined: --
I'll try to keep this brief.

Basically I need to adjust my mouse sensitivity for a certain game (not open source). I figured I'd try adjusting the Windows mouse sensitivity to compensate.

I did some hunting, and I went ahead and made a script that successfully changes the registry key "mousesensitivity" under the current user and then sends WM_SETTINGCHANGE.

The problem is that while the registry is updated (I see an hourglass pointer very briefly when it broadcasts), my mouse doesn't move any faster.

Now, I know I'm modifying the correct setting because I adjusted it using the control panel and refreshed RegEdit, and sure enough there it is: mousesensitivity value changes.

20 is the value I had set (the fastest Windows would allow through the control panel), and I was trying to set it to 60. I figured maybe 60 was out of bounds and just wasn't accepted (even though the key changed), so I tried changing it to 10. Well, again, the value changed, but the mouse movement didn't.

Maybe I'm missing something... or maybe I'm going about it the wrong way. Any ideas?

Thanks in advance, especially to Chris and the other very helpful guys here.

==============

highsensitivity := 10

;RegRead, normalsensitivity, HKEY_CURRENT_USER, Control Panel\Mouse, MouseSensitivity
normalsensitivity := 20

^!h::
RegWrite, REG_SZ, HKEY_CURRENT_USER, Control Panel\Mouse, MouseSensitivity, %highsensitivity%
SendMessage, 0x1A,,,, ahk_id 0xFFFF ; 0x1A is WM_SETTINGCHANGE

return

^!n::
RegWrite, REG_SZ, HKEY_CURRENT_USER, Control Panel\Mouse, MouseSensitivity, %normalsensitivity%
SendMessage, 0x1A,,,, ahk_id 0xFFFF ; 0x1A is WM_SETTINGCHANGE
return
==============

SKAN
  • Administrators
  • 9106 posts
  • Last active:
  • Joined: 26 Dec 2005

Maybe I'm missing something... or maybe I'm going about it the wrong way. Any ideas?


Some of these programmatic overrides we do to our system settings will not be effected until we log-off & log-in again. Sometimes, the nature of such a system-wide change might require a reboot too. User32.dll provides us a very useful function SystemParametersInfo() which we can use for such requirements.


This is what you need: Adjusting Mouse Sensitivity via hotkey
^!h::DllCall("SystemParametersInfo", Int,[color=red]113[/color], Int,0, UInt,[color=red]10[/color], Int,2)
^!n::DllCall("SystemParametersInfo", Int,[color=red]113[/color], Int,0, UInt,[color=red]20[/color], Int,2)

113 is SPI_SETMOUSESPEED
10 & 20 are values that indicate speed. ( Range: 1 to 20 )

Refer MSDN: SystemParametersInfo

Hope that makes you happy! :D

Esoteria
  • Guests
  • Last active:
  • Joined: --
Wow. Very wow. Fast reply and more clear than I could possibly have asked for. Even a link to more info on system parameters! You rock tremendously.

And it definitely works. The only problem is that it doesn't affect my mouse speed in the full screen application. I would normally pass this off as "Oh dang, the game doesn't let me change it in game. It's not in the source code, so there's no real way to do it except by switching out drivers" or something like that. The strange thing, though, is that it works normally on other machines. Now, I have the sensitivity at maximum here on the laptop, so maybe this program and other similar ones defaults to a certain sensitivity and ignores the Windows settings (actually, that would seem obvious at this point). In that case the question is why is my _default_ mouse sensitivity so low on this mouse/laptop combination, and... the real question...

...is there any way to up the mouse sensitivity beyond the threshold (perhaps by going to a lower level)?

Very helpful already, and thanks again.

ivanw
  • Members
  • 13 posts
  • Last active: Aug 23 2011 01:32 PM
  • Joined: 26 Dec 2006
Something to share on the subject with a simple script to toggle between low and user sensitivity:

; Autohotkey script "Toggle Mouse sensitivity"
;=================================================================================
SlowMouseSpeed      := 1
NormalMouseSpeed    := true ; State of Mouse pointer speed
UserMouseSpeed      := 0    ; Speed sensed before slow down
MouseThreshold1     := 6
MouseThreshold2     := 10
MouseEnhance        := 1

SPI_GETMOUSESPEED   := 0x70
SPI_SETMOUSESPEED   := 0x71
SPI_SETMOUSE        := 0x04 

;=================================================================================
*F17::   toggleMouseSpeed()

;=================================================================================
toggleMouseSpeed() {
    global
    ; SET LOW SPEED
    if( NormalMouseSpeed )
    {
        ; SENSE BEFORE
        DllCall("SystemParametersInfo", UInt,SPI_GETMOUSESPEED, UInt,0, UIntP,prevSpeed, UInt,0)

        ; Temporarily reduces the mouse cursor's speed.
        ; Retrieve the current speed so that it can be restored later
        DllCall("SystemParametersInfo", UInt,SPI_GETMOUSESPEED, UInt,0, UIntP,UserMouseSpeed, UInt,0)
        ; Slow down mouse speed
        DllCall("SystemParametersInfo", UInt,SPI_SETMOUSESPEED, UInt,0, UInt,SlowMouseSpeed, UInt,0)

        ; SENSE AFTER
        DllCall("SystemParametersInfo", UInt,SPI_GETMOUSESPEED, UInt,0, UIntP,currentSpeed, UInt,0)
        ToolTip, Mouse slow: %currentSpeed%/20

        ; REMEMBER CURRENT STATE
        NormalMouseSpeed := false
    }
    ; RESTORE SPEED
    else {
        ; SENSE BEFORE
        DllCall("SystemParametersInfo", UInt,SPI_GETMOUSESPEED, UInt,0, UIntP,prevSpeed, UInt,0)

        ; Restore the original speed.
        DllCall("SystemParametersInfo", UInt, SPI_SETMOUSESPEED, UInt,0, UInt,UserMouseSpeed, UInt,0)

        ; Restore the original speed acceleration thresholds and speed
        VarSetCapacity(MySet, 32, 0) 
        InsertInteger(MouseThreshold1, MySet, 0)
        InsertInteger(MouseThreshold2, MySet, 4)
        InsertInteger(MouseEnhance   , MySet, 8)
        DllCall("SystemParametersInfo", UInt,SPI_SETMOUSE, UInt,0, Str,MySet, UInt,1) 

        ; SENSE AFTER
        DllCall("SystemParametersInfo", UInt,SPI_GETMOUSESPEED, UInt,0, UIntP,currentSpeed, UInt,0)
        ToolTip, Mouse restored: %currentSpeed%/20

        ; REMEMBER CURRENT STATE
        NormalMouseSpeed := true
    }
    SetTimer, RemoveToolTip, 1000
}
;=================================================================================
InsertInteger(pInteger, ByRef pDest, pOffset = 0, pSize = 4) {
    ; Copy each byte in the integer into the structure as raw binary data. 
    Loop %pSize%
    DllCall("RtlFillMemory", "UInt",&pDest + pOffset + A_Index-1, "UInt", 1, "UChar", pInteger >> 8*(A_Index-1) & 0xFF) 
}
;=================================================================================
RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return

;=================================================================================



BETLOG
  • Members
  • 222 posts
  • Last active: Apr 07 2010 01:58 PM
  • Joined: 27 Nov 2006
You might also consider looking into "USB sample rate"

ivanw
  • Members
  • 13 posts
  • Last active: Aug 23 2011 01:32 PM
  • Joined: 26 Dec 2006

You might also consider looking into "USB sample rate"

This benchmark talks about this and it appears that results may depend on mouse technology. Anyway, this article is really worth reading!

BETLOG
  • Members
  • 222 posts
  • Last active: Apr 07 2010 01:58 PM
  • Joined: 27 Nov 2006
There are quite a few articles on this, just be aware that if you use some of them, even just the mouse analysis drivers, it's possible they can mess up your core OS mouse driver.... as i suspect happened to mine a while back, resuulting in a lot of double clicking when i only clicked once.
Completely removing the USB mouse device and it's driver, and reinstalling it and it's software wseems to have fixed it, but exercise a bit of caution.
Expect to need to reinstall mouse stuff.
(So learn how to navigate your OS without a mouse, or have a spare PS2 one on hand)

BETLOG
  • Members
  • 222 posts
  • Last active: Apr 07 2010 01:58 PM
  • Joined: 27 Nov 2006
I found this interface least painful for easily changing the driver and sampling rate:
<!-- m -->http://files.filefro... ... einfo.html<!-- m -->


MouseRateChecker is handy for a simple chekc of your mouse sampling rates:
<!-- m -->http://tscherwitschk...atechecker.html<!-- m -->

..and MiceJudge shows a good graph so you can see how 'lossy' your mouse hardware is. (and is possibly what screwed up my drivers)
<!-- m -->http://www.a4tech.co...icejudge-en.asp<!-- m -->
Posted Image

Before you change anything, check how much CPU you currently use by starting taskmanager (ctrl-shift-esc) and set :
view -> update speed -> high
then move your mouse around like crazy for a few seconds to see what kind of CPU impact there is.
Repeat for comparison after increasing USB sampling rates.

johnsom
  • Guests
  • Last active:
  • Joined: --
Thanks ivanw your code worked great for me.

bitcloud
  • Members
  • 29 posts
  • Last active: Feb 20 2010 04:03 AM
  • Joined: 30 Oct 2008
is there a way to increase the sensitivity beyond 20?

przemo
  • Guests
  • Last active:
  • Joined: --
hi, first answer is simple:
3::DllCall("SystemParametersInfo", Int,113, Int,0, UInt,10, Int,1)
2::DllCall("SystemParametersInfo", Int,113, Int,0, UInt,3, Int,1)

but second (that long code)... i dont think its good idea.

smaller code is better (for me). it sould be very fast for changing sensitive in real time (in rush with sniper gun, there is no time for pauses).

the problem is about not working first program INGAME. in desktop - ok, in game menu - ok, but in game that program does nothing (only blocks binded keys ^^).

if anyone know "simple" solution, that could help all fpp games community.

Ben Hill
  • Members
  • 5 posts
  • Last active: Jan 13 2011 03:46 PM
  • Joined: 04 Apr 2009
przemo,

I've been using a bit of code that I found and modified (not really understanding it). It looks mostly like yours, and it works, but can you explain the difference between the "int" and the "uint"?

My code:
DllCall("SystemParametersInfo", UInt,113, UInt,0, UInt,10, UInt,0)

Your code:
3::DllCall("SystemParametersInfo", Int,113, Int,0, UInt,10, Int,1)

And what about the "Uint,0" at the end of mine, as compared to the "Int,1" at the end of yours?

Thanks

przemo
  • Guests
  • Last active:
  • Joined: --
"And what about the "Uint,0" at the end of mine, as compared to the "Int,1" at the end of yours? "
its a very good question :). i dont understand it too (just copy, paste and hope it works ^^), but "uint" doesnt work in my enviroment.

i used first answer in that topic (short with two lines of code). that longer version doesnt work (64 bit xp pro).

  • Guests
  • Last active:
  • Joined: --
uint stands for unsigned integer, where int stands for integer. If you're working with values between 0 and 20, it shouldn't make a difference.

user1
  • Guests
  • Last active:
  • Joined: --

przemo,

I've been using a bit of code that I found and modified (not really understanding it). It looks mostly like yours, and it works, but can you explain the difference between the "int" and the "uint"?

My code:

DllCall("SystemParametersInfo", UInt,113, UInt,0, UInt,10, UInt,0)

Your code:
3::DllCall("SystemParametersInfo", Int,113, Int,0, UInt,10, Int,1)

And what about the "Uint,0" at the end of mine, as compared to the "Int,1" at the end of yours?

Thanks


That 1 vs. 0 makes a lot of difference.

Go to: http://msdn.microsof...ry ... 85).aspx and find fWinIni [in] section.