I downloaded AutoHotKey earlier today, in order to revert the scrolling on my ASUS laptop. I found a script where the reversion is made, and I understood it pretty easily.
This is the original script - it's working.
WheelUp::
Send {WheelDown}
Return
WheelDown::
Send {WheelUp}
Return
However the scroll speed is too fast, and I decided to make my own script that would slow down the scrolling. I'm currently studying my master in computer science, so i've been programming for a few years, so I thought the task was easy - it really is a simple script.
So i gave it a go, and I came up with some code - only problem is: It doesn't work! There's no compiling errors, and I can't figure out why. S the question is: Why doesn't the code below work? It doesn't scoll at all, but the scrolls are registered, as warning with too many inputs is enabled.
global UpSpeed := 0
global DownSpeed := 0
WheelUp::
global UpSpeed := global UpSpeed++
if (global UpSpeed > 2)
{
Send {WheelDown}
global UpSpeed := 0
}
Return
WheelDown::
global DownSpeed := global DownSpeed++
if (global UpSpeed > 2)
{
Send {WheelUp}
global DownSpeed := 0
}
Return
Rather than using counters and skipping wheel events, I suggest going with Sleep
. The problem with your approach is that in the worst case, it skips the first three wheel events. You don't want that to happen when you begin scrolling. That is, after a longer period of not scrolling, the first event should trigger a scroll immediately, and not after you've spinned the wheel multiple times.
By adjusting the duration of Sleep
to your needs, this code should do the trick:
$WheelUp::
Send {WheelDown}
Sleep, 75
Return
$WheelDown::
Send {WheelUp}
Sleep, 75
Return
To your code: The global
declaration only makes sense within functions, in the first line. Oddly enough, the code does compile, but is syntactical nonsense. Variables defined in the auto-execute section or (hotkey) labels are global anyway.
Furthermore, sending keys in AHK by default triggers its own hotkeys. Here, sending WheelDown
will ultimately result in sending WheelUp
and vice versa. The $
modifier will prevent that from happening.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With