How can I use the keyboard to simulate mousewheel scrolling with AutoHotkey?
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.
Solution 1:
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.
Solution 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
Solution 3:
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]