Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Script for changing mouse pointer speed


  • Please log in to reply
15 replies to this topic
Ticktockman
  • Members
  • 6 posts
  • Last active: Jul 26 2013 05:50 PM
  • Joined: 12 Apr 2006
Hi all - I travel with my laptop a lot between home and work, and every time I start I need to change my mouse pointer speed. (something to do with using external monitors)

Is there a script that can accomplish this in a hotkey? Something like:
Ctrl Win M for a predefined speedier level
and
Ctrl Shift Win M for a predefined lower level.

I've been able to open the Mouse Properties window with a hotkey, but can't get any combination of tabs and arrowing to change the pointer speed level.

Any ideas would be awesome!

Thanks,
Ticktockman

evl
  • Members
  • 1237 posts
  • Last active: Oct 20 2010 11:41 AM
  • Joined: 24 Aug 2005
Try searching the forum for more info, but here's the bit of script I use for toggling the mouse speed with one of the extra mouse buttons:

; GET INTIAL MOUSE SPEED:
; 0x70 (SPI_GETMOUSESPEED), third parameter is the speed (range is 1-20, 10 is default)
DllCall("SystemParametersInfo", UInt, 0x70, UInt, 0, UIntP, Mouse_Speed_Orig, UInt, 0) 
Mouse_Speed_Slow := Mouse_Speed_Orig * 0.75
Mouse_Speed_Slow := Floor(Mouse_Speed_Slow)
Return


XButton1::
  ; 0x71 (SPI_SETMOUSESPEED), third parameter is the speed (range is 1-20, 10 is default)
  DllCall("SystemParametersInfo", UInt, 0x70, UInt, 0, UIntP, Mouse_Speed_Now, UInt, 0) 
  If Mouse_Speed_Now =%Mouse_Speed_Orig%
    DllCall("SystemParametersInfo", UInt, 0x71, UInt, 0, UInt, Mouse_Speed_Slow, UInt, 0) 
  Else
    DllCall("SystemParametersInfo", UInt, 0x71, UInt, 0, UInt, Mouse_Speed_Orig, UInt, 0) 
Return

I think that's all the relevant code - it came from a much larger script I run.

evl
  • Members
  • 1237 posts
  • Last active: Oct 20 2010 11:41 AM
  • Joined: 24 Aug 2005
I should add that it saves the original mouse speed in the Mouse_Speed_Orig variable and you can adjust the factor it gets slowed by (or made faster by) by changing the value stored in Mouse_Speed_Slow.

  • Guests
  • Last active:
  • Joined: --
evl -

Thanks for responding! What you're describing sounds exactly like I need.

Can you clarify some points for a newbie?

Which number exactly controls what the speed gets changed to?

I copied your script exactly (only replacing XButton1 with a different hotkey: ^#M) That didn't seem to have any effect on mouse speed.

evl
  • Members
  • 1237 posts
  • Last active: Oct 20 2010 11:41 AM
  • Joined: 24 Aug 2005
I clarified it a little here:

; GET INTIAL MOUSE SPEED: 
; 0x70 (SPI_GETMOUSESPEED), third parameter is the speed (range is 1-20, 10 is default) 
DllCall("SystemParametersInfo", UInt, 0x70, UInt, 0, UIntP, Mouse_Speed_Orig, UInt, 0) 

Mouse_Speed_Slow := Mouse_Speed_Orig * 0.75 
Mouse_Speed_Slow := Floor(Mouse_Speed_Slow) 
; Or directly set the speed: Mouse_Speed_Slow =5
Return 

^#M:: 
  ; 0x71 (SPI_SETMOUSESPEED), third parameter is the speed (range is 1-20, 10 is default) 
  DllCall("SystemParametersInfo", UInt, 0x70, UInt, 0, UIntP, Mouse_Speed_Now, UInt, 0) 
  If Mouse_Speed_Now =%Mouse_Speed_Orig% 
    DllCall("SystemParametersInfo", UInt, 0x71, UInt, 0, UInt, Mouse_Speed_Slow, UInt, 0) 
  Else 
    DllCall("SystemParametersInfo", UInt, 0x71, UInt, 0, UInt, Mouse_Speed_Orig, UInt, 0) 
Return 

See the lines just before the first Return for setting the speed (Mouse_Speed_Slow). If you want to set a specific number rather than a relative number (as the current code does by multiplying by 0.75 then rounding the number) then comment out those 2 lines and uncomment the line underneath.

The hotkey is a toggle, you only need to press it once to switch to the slow mouse speed and then press it again to switch back to the original speed.

Ticktockman
  • Members
  • 6 posts
  • Last active: Jul 26 2013 05:50 PM
  • Joined: 12 Apr 2006
evl -

Thanks for clarifying - that did the trick! I'm now able to toggle back and forth between my two mouse pointer speeds easily.

NOW - I could only get this to work as it's own script. At first I dropped it into my script that also contains my program launch shortcuts and Excel shortcuts. It doesn't work there - I'm assuming because it's conflicting with something else. Is there some bit I can add at the beginning to set it apart from everything else?

I can post my entire .ahk file if needed.

Ticktockman

evl
  • Members
  • 1237 posts
  • Last active: Oct 20 2010 11:41 AM
  • Joined: 24 Aug 2005
The first half of the script (before the hotkey line) needs to go in the auto-execute part of your script (the section before the first Return or first hotkey:: ). The hotkey section can go anywhere in the script. Nothing special about this script, the same applies to any script.

hrsy
  • Guests
  • Last active:
  • Joined: --
hey just wanna say thanks for this - I was looking for the exact same thing.

  • Guests
  • Last active:
  • Joined: --
is there a way to make this work in bf2? it works in the game until you click "Join Game" then the game blocks it somehow.

snuuz
  • Members
  • 2 posts
  • Last active: Oct 13 2006 05:02 AM
  • Joined: 13 Oct 2006
Thanks. Here's a different variant. I wanted a .ahk file that I can double-click or execute to set a specific mouse speed. The code below shows how this is done. I've thrown in a simple splash screen to tell me what's going on.

; This script changes the mouse speed to the value kSpeed

kSpeed = 8

Progress, b2 zh0 fs18  w200, Setting mouse speed to %kSpeed%

; 0x70 (SPI_GETMOUSESPEED), third parameter is the speed (range is 1-20, 10 is default)
DllCall("SystemParametersInfo", UInt, 0x71, UInt, 0, UInt, kSpeed, UInt, 0)

Sleep, 2000
Progress, Off

Hope it will help somebody else.

  • Guests
  • Last active:
  • Joined: --
I'm just a guest, but I have kinda like the same problem here. I have a laptop, and I only use external mice. One is at home, and one is traveling with me. However, both mice are at a different speed, so I have to manually change it every time I switch them... is there any way to change the speed in just one click?


If the code posted here is what I need, then, how am I going to install it? Should it be put into a .cfg file? and where should this .cfg file be put? Thank you in advance. :)

lilalurl.T32
  • Members
  • 391 posts
  • Last active: Jul 05 2011 03:39 PM
  • Joined: 17 May 2007

If the code posted here is what I need, then, how am I going to install it? Should it be put into a .cfg file? and where should this .cfg file be put? Thank you in advance. :)


No, it is an AutoHotKey script.
Download AutoHotKey, install, copy the code to a text file with the .ahk extension and double click the ahk file.
http://www.autohotkey.com/

The script may or may not help you but should produce a result. You may have to modify some values (you are told what they do in the comments (the text in green)).
Also, read the introduction in the AHK manual, it is quite useful to begin with AHK
________
FORD INDIA PICTURE

Isherwood
  • Guests
  • Last active:
  • Joined: --
Just wanted to say thanks for this. It's the only good solution I found.

I ended up using snuuz's version, and I simply tacked two script files to my Start menu - Logitech.ahk and Microsoft.ahk. To use either mouse, I simply click Start and the shortcut. Quick and easy!

BTW, my Logitech wireless desktop mouse likes speed 6, and my Microsoft RF wireless likes 18. Quite a range, which is why I needed this so badly.

IjustWanaShoot
  • Guests
  • Last active:
  • Joined: --

I clarified it a little here:

; GET INTIAL MOUSE SPEED: 
; 0x70 (SPI_GETMOUSESPEED), third parameter is the speed (range is 1-20, 10 is default) 
DllCall("SystemParametersInfo", UInt, 0x70, UInt, 0, UIntP, Mouse_Speed_Orig, UInt, 0) 

Mouse_Speed_Slow := Mouse_Speed_Orig * 0.75 
Mouse_Speed_Slow := Floor(Mouse_Speed_Slow) 
; Or directly set the speed: Mouse_Speed_Slow =5
Return 

^#M:: 
  ; 0x71 (SPI_SETMOUSESPEED), third parameter is the speed (range is 1-20, 10 is default) 
  DllCall("SystemParametersInfo", UInt, 0x70, UInt, 0, UIntP, Mouse_Speed_Now, UInt, 0) 
  If Mouse_Speed_Now =%Mouse_Speed_Orig% 
    DllCall("SystemParametersInfo", UInt, 0x71, UInt, 0, UInt, Mouse_Speed_Slow, UInt, 0) 
  Else 
    DllCall("SystemParametersInfo", UInt, 0x71, UInt, 0, UInt, Mouse_Speed_Orig, UInt, 0) 
Return 

See the lines just before the first Return for setting the speed (Mouse_Speed_Slow). If you want to set a specific number rather than a relative number (as the current code does by multiplying by 0.75 then rounding the number) then comment out those 2 lines and uncomment the line underneath.

The hotkey is a toggle, you only need to press it once to switch to the slow mouse speed and then press it again to switch back to the original speed.



hey,

evl

Anyway to make it into held down button instead of toggle?
Only way I could do it is shown below but for some reason doesnt work in every game so cant realy relay on it always. maybe theres easier way.

; GET INTIAL MOUSE SPEED:
; 0x70 (SPI_GETMOUSESPEED), third parameter is the speed (range is 1-20, 10 is default)
DllCall("SystemParametersInfo", UInt, 0x70, UInt, 0, UIntP, Mouse_Speed_Orig, UInt, 0)

Mouse_Speed_Slow := Mouse_Speed_Orig * 0.5
Mouse_Speed_Slow := Floor(Mouse_Speed_Slow)
; Or directly set the speed: Mouse_Speed_Slow =5
Return

space::
sendinput {f5}
loop, 1
{
KeyWait, space
sendinput {f5}
}
return

f5::
; 0x71 (SPI_SETMOUSESPEED), third parameter is the speed (range is 1-20, 10 is default)
DllCall("SystemParametersInfo", UInt, 0x70, UInt, 0, UIntP, Mouse_Speed_Now, UInt, 0)
If Mouse_Speed_Now =%Mouse_Speed_Orig%
DllCall("SystemParametersInfo", UInt, 0x71, UInt, 0, UInt, Mouse_Speed_Slow, UInt, 0)
Else
DllCall("SystemParametersInfo", UInt, 0x71, UInt, 0, UInt, Mouse_Speed_Orig, UInt, 0)
Return

~/::Suspend
+~/::Suspend


let me know on [email protected] or here. that would realy put me to peace.

adiksw
  • Members
  • 1 posts
  • Last active: Aug 02 2014 01:20 PM
  • Joined: 21 Jul 2014

Thank you very much for the script. Is it possible to enable and disable: Enhance pointer precision via script?