Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slowing scroll speed down with autohotkey

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
like image 504
Andersnk Avatar asked Oct 15 '25 18:10

Andersnk


1 Answers

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.

like image 126
MCL Avatar answered Oct 18 '25 08:10

MCL