14

I'm looking for a way to scroll with the keyboard using AutoHotkey. It would be also great if I could tweak scrolling speed somehow.

2

5 Answers 5

14

You can use the MouseClick function to simulate the mouse wheel. Here's an example script that lets you scroll by holding down the CapsLock key and pressing 'w' to scroll up or 's' to scroll down:

CapsLock & w::
 MouseClick,WheelUp,,,10,0,D,R
return

CapsLock & s::
 MouseClick,WheelDown,,,10,0,D,R
return

You can make it go faster by changing the 10 to a larger value. It is the number of "detents" you want the wheel to scroll through.

There is also a script at autohotkey.com that sets up all the mouse buttons and movements on the NumPad, though I've not tried it.

2
  • I would like to assign this command to keys: ctrl+alt+up for scrolling up and ctrl+alt+down for scrolling down But nothing is happening, scroll is not working. Please help, thx.
    – IGRACH
    Jan 26, 2016 at 2:03
  • 1
    A very nice answer sir Jul 9, 2017 at 11:26
2

This is a script I just worked up. Press 0 and Up or Down Arrow keys to operate. If you don't have a numpad on your computer, you can always customize the two keys as you see fit. It works so that you may hold down 0 and an arrow key and continue speed scrolling. Perhaps better than a scroll wheel itself?

0 & Up::
Loop
{
Send {WheelUp}
GetKeyState, T, Down
If T=U ; U is a state for up, D is a state for down
  Break
}
Return

0 & Down::
Loop
{
Send {WheelDown}
GetKeyState, T, Down
If T=U ; U is a state for up, D is a state for down
  Break
}
Return
1
  • This is great, except that it seems to make the 0 key unusable for any other purpose
    – Ben Farmer
    Oct 12, 2020 at 1:25
1

Mouse Wheel Hotkeys [Windows NT/2000/XP or later]

Hotkeys that fire upon turning the mouse wheel are supported via the key names WheelDown and WheelUp. WheelLeft and WheelRight are also supported in v1.0.48+, but have no effect on operating systems older than Windows Vista. Here are some examples of mouse wheel hotkeys:

MButton & WheelDown::MsgBox You turned the mouse wheel down while holding down the middle button.
^!WheelUp::MsgBox You rotated the wheel up while holding down Control+Alt.

In v1.0.43.03+, the built-in variable A_EventInfo contains the amount by which the wheel was turned, which is typically 1. However, A_EventInfo can be greater or less than 1 under the following circumstances:

  • If the mouse hardware reports distances of less than one notch, A_EventInfo may contain 0;
  • If the wheel is being turned quickly (depending on type of mouse), A_EventInfo may be greater than 1. A hotkey like the following can help analyze your mouse: ~WheelDown::ToolTip %A_EventInfo%

Some of the most useful hotkeys for the mouse wheel involve alternate modes of scrolling a window's text. For example, the following pair of hotkeys scrolls horizontally instead of vertically when you turn the wheel while holding down the left Control key:

~LControl & WheelUp::  ; Scroll left.  
ControlGetFocus, fcontrol, A  
Loop 2  ; <-- Increase this value to scroll faster.  
    SendMessage, 0x114, 0, 0, %fcontrol%, A  ; 0x114 is WM_HSCROLL and the 0 after it is SB_LINELEFT.  
return  

~LControl & WheelDown::  ; Scroll right.  
ControlGetFocus, fcontrol, A  
Loop 2  ; <-- Increase this value to scroll faster.  
    SendMessage, 0x114, 1, 0, %fcontrol%, A  ; 0x114 is WM_HSCROLL and the 1 after it is SB_LINERIGHT.  
return  

Finally, since mouse wheel hotkeys generate only down-events (never up-events), they cannot be used as key-up hotkeys.

[Source: Here]

1

I recommend solution from http://lifehacker.com/5626708/use-autohotkey-to-scroll-backwards-in-the-command-prompt-by-keyboard

Personally I prefer use LWin key as modifier (to avoid collision with Emacs key binding):

LWin & PgUp::
  Send {WheelUp}
Return

LWin & PgDn::
  Send {WheelDown}
Return

This solution distinct from yhw42 solution as much simple to understand and it uses standard Windows settings for scrolling (how fast to scroll).

NOTE This techniques useful on notebooks (as touchpad can be useless for some user) and for users that dislike mouse. Mouse event send to active GUI elements, so you need proper place mouse position.

0

I'll include this solution as i've used it successfully and it looks simpler than the other ones mentioned. You can adjust the number from 3 to whatever to change the amount of scrolling.

The caret symbol is ctrl key. So ctrl+pageup and ctrl+pagedown

^PgUp::
Send, {wheelup 3}
return

^PgDn::
Send {wheeldown 3}
return

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .