AHK: Use Arrow Keys as Modfifiers
May 6, 2021โข391 words
Intro
The following AutoHotKey script enables you to use Ctrl + Alt followed by an arrow key to target PgUp, PgDwn, Home and End.
These function keys are seriously underated, they allow you to navigate code, documents, webpages etc much faster than using the arrow keys alone. It means you don't have to reach so far across the keyboard, and useful for smaller keyboards that don't have these dedicated keys
This is inspired by using Alt
+ Left
/ Right
arrow, which (in most systems) moves the cursor forward/ backward by one word at a time (rather than a single character)
Usage
Moving the cursor/ navigating:
Ctrl
+Alt
+Up
-->Page Up
Ctrl
+Alt
+Down
-->Page Down
Ctrl
+Alt
+Left
-->Home
Ctrl
+Alt
+Right
-->End
You can also use this combination along with the Shift key, in order to select text between the cursors start and end point:
Ctrl
+Alt
+Shift
+Up
--> Will select entire document above cursorCtrl
+Alt
+Shift
+Down
--> Will select entire document below cursorCtrl
+Alt
+Shift
+Left
--> Will select entire line to the leftCtrl
+Alt
+Shift
+Right
--> Will select all text from the cursor, to the end of the line
The Script
!^*Up::
GetKeyState, state, Shift
if state = D
Send +{PgUp}
else
Send {PgUp}
return
!^*Down::
GetKeyState, state, Shift
if state = D
Send +{PgDn}
else
Send {PgDn}
return
!^*Left::
GetKeyState, state, Shift
if state = D
Send +{Home}
else
Send {Home}
return
!^*Right::
GetKeyState, state, Shift
if state = D
Send +{End}
else
Send {End}
return
Installation
First ensure that you have the latest version of AutoHotKey installed on your system. Copy the above script, and save it in a file with a .ahk
extension. Finally, double click on the file, and it should now be running. You will now see the AHK icon in your task bar, and should be able to use the above key bindings.
Note that AutoHotKey is only available for Windows-based systems, but similar functionality can usually be achieved natively on Linux, through your WM, or using a utility such as AutoKey for X11.