I was impressed by the smoothness of the mouse movement using MicroTimer, but the cursor got often stuck when quickly switching directions.
Code: Select all
; NOTE: While a script like this is running, the entire operating system and all applications are
; affected by timeBeginPeriod below.
SetBatchLines -1 ; Ensures maximum effectiveness of this method.
ntchs:=2
SleepDuration = 1 ; This can sometimes be finely adjusted (e.g. 2 is different than 3) depending on the value below.
TimePeriod = 3 ; Try 7 or 3. See comment below.
; On a PC whose sleep duration normally rounds up to 15.6 ms, try TimePeriod=7 to allow
; somewhat shorter sleeps, and try TimePeriod=3 or less to allow the shortest possible sleeps.
;~ DllCall("Winmm\timeBeginPeriod", uint, TimePeriod) ; Affects all applications, not just this script's DllCall("Sleep"...), but does not affect SetTimer.
~Right::
loop
{
DllCall("user32.dll\mouse_event", "UInt", 0x0001, "UInt", 1*ntchs, "UInt", 0, "UInt", 0, "UPtr", 0)
DllCall("Sleep", UInt, SleepDuration) ; Must use DllCall instead of the Sleep command.
if !GetKeyState("Right", "P")
break
}
DllCall("Winmm\timeEndPeriod", UInt, TimePeriod) ; Should be called to restore system to normal.
return
~Left::
loop
{
DllCall("user32.dll\mouse_event", "UInt", 0x0001, "UInt", -1*ntchs, "UInt", 0, "UInt", 0, "UPtr", 0)
DllCall("Sleep", UInt, SleepDuration) ; Must use DllCall instead of the Sleep command.
if !GetKeyState("Left", "P")
break
}
DllCall("Winmm\timeEndPeriod", UInt, TimePeriod) ; Should be called to restore system to normal.
return
~Down::
loop
{
DllCall("user32.dll\mouse_event", "UInt", 0x0001, "UInt", 0, "UInt", 1*ntchs, "UInt", 0, "UPtr", 0)
DllCall("Sleep", UInt, SleepDuration) ; Must use DllCall instead of the Sleep command.
if !GetKeyState("Down", "P")
break
}
DllCall("Winmm\timeEndPeriod", UInt, TimePeriod) ; Should be called to restore system to normal.
return
~Up::
loop
{
DllCall("user32.dll\mouse_event", "UInt", 0x0001, "UInt", 0, "UInt", -1*ntchs, "UInt", 0, "UPtr", 0)
DllCall("Sleep", UInt, SleepDuration) ; Must use DllCall instead of the Sleep command.
if !GetKeyState("Up", "P")
break
}
DllCall("Winmm\timeEndPeriod", UInt, TimePeriod) ; Should be called to restore system to normal.
return
^Esc::
DllCall("Winmm\timeEndPeriod", UInt, TimePeriod) ; Should be called to restore system to normal.
ExitApp
return