Slow down mouse

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
akirofe
Posts: 149
Joined: 05 Apr 2021, 21:54

Slow down mouse

Post by akirofe » 07 Aug 2022, 02:22

Hi guys :)

Please help me to get this work with Ctrl key instead? Thank you very much!!

Code: Select all

; Example: This is a hotkey that temporarily reduces the mouse cursor's speed, which facilitates precise positioning.
; Hold down F1 key to slow down the cursor. Release it to return to original speed.
F1::
SPI_GETMOUSESPEED = 0x70
SPI_SETMOUSESPEED = 0x71
; Retrieve the current speed so that it can be restored later:
DllCall("SystemParametersInfo", UInt, SPI_GETMOUSESPEED, UInt, 0, UIntP, OrigMouseSpeed, UInt, 0)
; Now set the mouse to the slower speed specified in the next-to-last parameter (the range is 1-20, 10 is default):
DllCall("SystemParametersInfo", UInt, SPI_SETMOUSESPEED, UInt, 0, Ptr, 3, UInt, 0)
KeyWait F1  ; This prevents keyboard auto-repeat from doing the DllCall repeatedly.
return

F1 up::DllCall("SystemParametersInfo", UInt, 0x71, UInt, 0, Ptr, OrigMouseSpeed, UInt, 0)  ; Restore the original speed.
*** Thank you for reading. I am not in coding and know almost nothing about professional coding, hope for your patience and deeply appreciate any of your kind helps. My current interest in this awesome AHK is due to that my work is graphical ((architect/CAD) and, to reduce strains, my right hand is better off not leaving the mouse (an MMO mouse that has 12 side keys which I maps a lot of F keys and other keys in) as much as possible. All the best you lovely coders! ***

Rohwedder
Posts: 7608
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Slow down mouse

Post by Rohwedder » 07 Aug 2022, 02:39

Hallo,
try:

Code: Select all

; Example: This is a hotkey that temporarily reduces the mouse cursor's speed, which facilitates precise positioning.
; Hold down Ctrl key to slow down the cursor. Release it to return to original speed.
~Ctrl::
IF OrigMouseSpeed
	Return
SPI_GETMOUSESPEED = 0x70
SPI_SETMOUSESPEED = 0x71
; Retrieve the current speed so that it can be restored later:
DllCall("SystemParametersInfo", UInt, SPI_GETMOUSESPEED, UInt, 0, UIntP, OrigMouseSpeed, UInt, 0)
; Now set the mouse to the slower speed specified in the next-to-last parameter (the range is 1-20, 10 is default):
DllCall("SystemParametersInfo", UInt, SPI_SETMOUSESPEED, UInt, 0, Ptr, 3, UInt, 0)
Return
~Ctrl up::
DllCall("SystemParametersInfo", UInt, 0x71, UInt, 0, Ptr, OrigMouseSpeed, UInt, 0)  ; Restore the original speed.
OrigMouseSpeed =
Return

akirofe
Posts: 149
Joined: 05 Apr 2021, 21:54

Re: Slow down mouse

Post by akirofe » 07 Aug 2022, 17:46

Rohwedder wrote:
07 Aug 2022, 02:39
Hallo,
try:

Code: Select all

; Example: This is a hotkey that temporarily reduces the mouse cursor's speed, which facilitates precise positioning.
; Hold down Ctrl key to slow down the cursor. Release it to return to original speed.
~Ctrl::
IF OrigMouseSpeed
	Return
SPI_GETMOUSESPEED = 0x70
SPI_SETMOUSESPEED = 0x71
; Retrieve the current speed so that it can be restored later:
DllCall("SystemParametersInfo", UInt, SPI_GETMOUSESPEED, UInt, 0, UIntP, OrigMouseSpeed, UInt, 0)
; Now set the mouse to the slower speed specified in the next-to-last parameter (the range is 1-20, 10 is default):
DllCall("SystemParametersInfo", UInt, SPI_SETMOUSESPEED, UInt, 0, Ptr, 3, UInt, 0)
Return
~Ctrl up::
DllCall("SystemParametersInfo", UInt, 0x71, UInt, 0, Ptr, OrigMouseSpeed, UInt, 0)  ; Restore the original speed.
OrigMouseSpeed =
Return
Thank you very much Rohwedder! It worked nicely!!
For my knowledge only, may I know what the does the "~" do and/or where can I read about those to not waste people's precious time with such basic question...? Thankyou again Rohwedder!!
*** Thank you for reading. I am not in coding and know almost nothing about professional coding, hope for your patience and deeply appreciate any of your kind helps. My current interest in this awesome AHK is due to that my work is graphical ((architect/CAD) and, to reduce strains, my right hand is better off not leaving the mouse (an MMO mouse that has 12 side keys which I maps a lot of F keys and other keys in) as much as possible. All the best you lovely coders! ***

Post Reply

Return to “Ask for Help (v1)”