Alt + arrow keys for Home/End/PgUp/PgDown

Post your working scripts, libraries and tools
loopernow
Posts: 6
Joined: 17 Mar 2019, 14:18

Alt + arrow keys for Home/End/PgUp/PgDown

17 Mar 2019, 16:25

This is a really basic script; I'm by no means a programmer but I just wanted to share this because I have a laptop that has no PgUp/PgDn/Home/End keys but it has labels for same on the arrow keys and it has a Fn key on the other side of the space bar to press with the arrow keys to get those functions...which I found really useless; it takes way too long to look back and forth to find and press these keys in combination.

So this script uses Alt like the Fn key, so that you can use Alt on either side of the keyboard with the arrow keys to get Home, End, Page Up, Page Down.

Universal
Alt + left arrow = Home
Alt + right arrow = End
Alt + up arrow = PgUp
Alt + down arrow = PgDn

In addition you can combine any of the above shortcuts with Shift or Ctrl or both, to select text or move the cursor in various ways in text editors and word processors.

One side effect of these new shortcuts is that the Alt + left/right arrows shortcuts in browsers and file browsers to go back/forward are replaced. So I have added the alternate shortcuts below for those functions in those programs. You can add your own window classes to the script if you use a particular browser that I don't have listed.

In browsers and file browsers
Alt + left bracket '[' = Back
Alt + right bracket ']' = Forward
Alt + period '.' = Up one directory level

Lastly, I can't natively use Win + Home on my laptop (a Windows 10 shortcut to hide all windows except the active one) even with the Fn key, so I added that to the script too.

Universal
Win + Alt + left arrow = Win + Home

I was inspired to do this based on a script that used right Shift + arrow keys but I wanted something a little bit more universal that wouldn't interfere with using the right Shift key in combination with other keys to select text and move the cursor.

I hope this is useful! Here is the script:

Code: Select all

; Ensures a consistent starting directory.
SetWorkingDir %A_ScriptDir%  

; -----------------------------------------------------------
; Sane Navigation Shortcuts with Alt
;
; An easier and more consistent way to send PgUp/PgDown/
; Home/End for laptops with no dedicated keys for these
; functions.
;
; The following shortcuts recruit Alt as a better Fn key, 
; since Alt is on both sides of the keyboard and isn't used
; much otherwise.
;
; Alt + left arrow = Home
; Alt + right arrow = End
; Alt + up arrow = PgUp
; Alt + down arrow = PgDn
;
; Each Alt key (right and left) must be referred to specific-
; ally, else problems arise. Also, it's sometimes necessary 
; to leave out {Alt Up}.
; -----------------------------------------------------------

; Win + Alt + Left Arrow sends Win-Home
#!Left:: send {Win Up}{Alt Up}#{Home}

; PgUp/Down + Home/End shortcuts (Alt + arrow keys):

; first using right-Alt 

; + arrow keys
>!Up::send {RAlt Up}{PgUp}
>!Down::send {RAlt Up}{PgDn}
>!Left::send {RAlt Up}{Home}
>!Right::send {RAlt Up}{End}

; Ctrl + PgUp/Down, Home/End
; function for text editors and word processors
>!^Up::send {Alt Up}{Crtl Up}^{PgUp}
>!^Down::send {Alt Up}{Crtl Up}^{PgDn}
>!^Left::send {Alt Up}{Crtl Up}^{Home}
>!^Right::send {Alt Up}{Crtl Up}^{End}

; Shift + PgUp/Down, Home/End
; function for text editors and word processors
>!+Up::send {Alt Up}{Shift Up}+{PgUp}
>!+Down::send {Alt Up}{Shift Up}+{PgDn}
>!+Left::send {Alt Up}{Shift Up}+{Home}
>!+Right::send {Alt Up}{Shift Up}+{End}

; Ctrl + Shift + PgUp/Down, Home/End
; function for text editors and word processors
>!^+Up::send {Alt Up}{Crtl Up}{Shift Up}^+{PgUp}
>!^+Down::send {Alt Up}{Crtl Up}{Shift Up}^+{PgDn}
>!^+Left::send {Alt Up}{Crtl Up}{Shift Up}^+{Home}
>!^+Right::send {Alt Up}{Crtl Up}{Shift Up}^+{End}

; now using left Alt too

; + arrow keys
<!Up::send {RAlt Up}{PgUp}
<!Down::send {RAlt Up}{PgDn}
<!Left::send {RAlt Up}{Home}
<!Right::send {RAlt Up}{End}

; Ctrl + PgUp/Down, Home/End
; function for text editors and word processors
<!^Up::send {Alt Up}{Crtl Up}^{PgUp}
<!^Down::send {Alt Up}{Crtl Up}^{PgDn}
<!^Left::send {Alt Up}{Crtl Up}^{Home}
<!^Right::send {Alt Up}{Crtl Up}^{End}

; Shift + PgUp/Down, Home/End
; function for text editors and word processors
<!+Up::send {Alt Up}{Shift Up}+{PgUp}
<!+Down::send {Alt Up}{Shift Up}+{PgDn}
<!+Left::send {Alt Up}{Shift Up}+{Home}
<!+Right::send {Alt Up}{Shift Up}+{End}

; Ctrl + Shift + PgUp/Down, Home/End
; function for text editors and word processors
<!^+Up::send {Alt Up}{Crtl Up}{Shift Up}^+{PgUp}
<!^+Down::send {Alt Up}{Crtl Up}{Shift Up}^+{PgDn}
<!^+Left::send {Alt Up}{Crtl Up}{Shift Up}^+{Home}
<!^+Right::send {Alt Up}{Crtl Up}{Shift Up}^+{End}

; Alt + left/right arrow keys conflicts with existing short-
; cuts in file/internet browsers (plus Alt + up arrow con-
; flicts in Explorer). So, use OS X keyboard shortcuts in 
; those programs, instead (plus an imperfect compromise 
; to replace Alt + up).
;
; In OS X, to go back/forward, Command + left and right 
; brackets ('[]') are used. So, the same are set up here,
; except using Alt instead of Command.
;
; An imperfect replacement for Alt-Up (or Command-Up in
; OS X) is Alt + '.' (period). The mnemonic for this is that
; '..' is used on the command line to go up one level in a
; directory.

; --Test if browser or Explorer is active window--
#If WinActive("ahk_class MozillaWindowClass") or WinActive("ahk_class Chrome_WidgetWin_1") or WinActive("ahk_class CabinetWClass")

; Alt-arrow navigation shortcuts for those programs
<!.::send !{Up}
<![::send !{Left}
<!]::send !{Right}

>!.::send !{Up}
>![::send !{Left}
>!]::send !{Right}

; --end Alt shortcuts--


; --Not used--

; I considered using right-Shift plus arrow keys for 
; PgUp/Down and Home/End for browsers and Explorer, since
; Alt + right/left arrows, and Alt + up arrow for Explorer, 
; are already shortcuts in these programs. But, this 
; seemed like too much cognitive dissonance. However, if 
; you want to use that scheme, the below may be useful.

; Exclude browsers and Explorer to avoid conflict with Alt +
; left/right arrow conflicts for Back/Forward shortcuts in
; those programs (and Alt + up arrow in Explorer for "up one
; directory level")
; #If !(WinActive("ahk_class MozillaWindowClass") OR WinActive("ahk_class Chrome_WidgetWin_1") OR WinActive("ahk_class CabinetWClass"))

; >+Up::send {RShift Up}{PgUp}
; >+Down::send {RShift Up}{PgDn}
; >+Left::send {RShift Up}{Home}
; >+Right::send {RShift Up}{End}
User avatar
Cerberus
Posts: 169
Joined: 12 Jan 2016, 15:46

Re: Alt + arrow keys for Home/End/PgUp/PgDown

17 Mar 2019, 21:04

That looks neat and well thought out.
DRocks
Posts: 561
Joined: 08 May 2018, 10:20

Re: Alt + arrow keys for Home/End/PgUp/PgDown

18 Mar 2019, 01:47

Cool idea thanks for sharing
allopatry
Posts: 1
Joined: 30 Sep 2020, 09:26
GitHub: allopatry

Re: Alt + arrow keys for Home/End/PgUp/PgDown

30 Sep 2020, 09:52

Apologies for necro-posting. I registered with the forum just to express thanks for sharing this script. It was exactly what I was looking for after getting a new laptop with a weird keyboard layout. I am especially impressed with how you handle the browsers in an application-specific manner. I was experiencing interference with Firefox's default hotkeys when I tried setting up my own ahk script. Your solution is more elegant and specific. More importantly, it works!
jkenny23
Posts: 1
Joined: 12 Feb 2021, 20:29

Re: Alt + arrow keys for Home/End/PgUp/PgDown

12 Feb 2021, 20:33

I'm trying to use your "shift+end"/"shift+home" combos to bind the right shift+ctrl key plus left/right arrow keys to these combos but it is not holding down shift for the selection part. I've tried quite a few variants but nothing is working so far to produce the output I want (select full beginning or end of sentence to cursor with 1 key combo). My laptop is an Asus G14 that didn't have home/end/pgup/pgdn keys natively.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: emrekarahan0001 and 24 guests