AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Adjusting Mouse Sensitivity via hotkey

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Esoteria
Guest





PostPosted: Sat Dec 09, 2006 8:07 pm    Post subject: Adjusting Mouse Sensitivity via hotkey Reply with quote

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
==============
Back to top
SKAN



Joined: 26 Dec 2005
Posts: 6839

PostPosted: Sat Dec 09, 2006 9:02 pm    Post subject: Reply with quote

Esoteria wrote:
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
Code:
^!h::DllCall("SystemParametersInfo", Int,113, Int,0, UInt,10, Int,2)
^!n::DllCall("SystemParametersInfo", Int,113, Int,0, UInt,20, 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! Very Happy
_________________
Suresh Kumar A N
Back to top
View user's profile Send private message
Esoteria
Guest





PostPosted: Sat Dec 09, 2006 11:33 pm    Post subject: Reply with quote

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.
Back to top
ivanw



Joined: 26 Dec 2006
Posts: 12
Location: Paris, France

PostPosted: Tue Dec 26, 2006 11:34 pm    Post subject: Reply with quote

Something to share on the subject with a simple script to toggle between low and user sensitivity:

Code:

; 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

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

Back to top
View user's profile Send private message
BETLOG



Joined: 27 Nov 2006
Posts: 219
Location: Queensland, Australia

PostPosted: Wed Dec 27, 2006 11:09 am    Post subject: Reply with quote

You might also consider looking into "USB sample rate"
Back to top
View user's profile Send private message
ivanw



Joined: 26 Dec 2006
Posts: 12
Location: Paris, France

PostPosted: Wed Dec 27, 2006 10:42 pm    Post subject: Reply with quote

BETLOG wrote:
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!
Back to top
View user's profile Send private message
BETLOG



Joined: 27 Nov 2006
Posts: 219
Location: Queensland, Australia

PostPosted: Thu Dec 28, 2006 8:30 am    Post subject: Reply with quote

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)
Back to top
View user's profile Send private message
BETLOG



Joined: 27 Nov 2006
Posts: 219
Location: Queensland, Australia

PostPosted: Thu Dec 28, 2006 9:00 am    Post subject: Reply with quote

I found this interface least painful for easily changing the driver and sampling rate:
http://files.filefront.com/usbmrs11exe/;6313268;;/fileinfo.html


MouseRateChecker is handy for a simple chekc of your mouse sampling rates:
http://tscherwitschke.de/mouseratechecker.html

..and MiceJudge shows a good graph so you can see how 'lossy' your mouse hardware is. (and is possibly what screwed up my drivers)
http://www.a4tech.com/en/micejudge-en.asp


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.
Back to top
View user's profile Send private message
johnsom
Guest





PostPosted: Sat Jun 14, 2008 1:25 pm    Post subject: Reply with quote

Thanks ivanw your code worked great for me.
Back to top
bitcloud



Joined: 30 Oct 2008
Posts: 5

PostPosted: Tue Jan 13, 2009 9:29 am    Post subject: Super Sensitive Reply with quote

is there a way to increase the sensitivity beyond 20?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group