8/15/24

Simple AutoHotkey Scripts on Startup

As someone who uses my PC almost everyday, I just want to do stuff quick and easy.

milk and honey bee xda keycaps

Listening to Spotify or my local music files on WACUP, I just want to assign keys on my mechanical keyboard to quickly play/pause songs or mute the volume. These keys should be universal and persistent, would work when the window is minimized or not. How to achieve that? By using hotkeys, of course.

A hotkey or keyboard shortcut is a key or combination of keys that performs a certain action when pressed. We can assign hotkeys by using a program called AutoHotkey.

What's AutoHotkey?

AutoHotkey makes assigning specific keys on my keyboard a breeze. I have a very simple purpose for it, but even so it greatly improves my QOIL (Quality of Internet Life). Universal play/pause, mute volume and one key Print Screen (my 65% keyboard doesn't have one) are good enough for my usage. There are more complicated AutoHotkey scripts that deal with more complicated tasks, but those aren't my jam so we'll leave those to the experts. But feel free to explore them.

How to use AutoHotkey?

By installing the AutoHotkey application and making a AutoHotkey script/s.

This is my script that you can use or whatever.

qabej.ahk code:

PgUp::PrintScreen
PgDn::Media_Play_Pause
;
;Right Ctrl as >^
;
>^Right::Media_Next
>^Left::Media_Prev
>^Up::Volume_Up
>^Down::Volume_Down
>^PgDn::Volume_Mute

Script explanation:

Syntax for the built-in remapping feature is OriginKey::DestinationKey. x::z means x key becomes z key.

PgUp::PrintScreen [Pressing Page Up key triggers Print Screen (PrtSc) key]
PgDn::Media_Play_Pause [Pressing Page Down key triggers media play/pause]
;
;Right Ctrl as >^ [RControl (or RCtrl) key corresponds to the >^ hotkey prefix]
;
>^Right::Media_Next [RControl key + Right arrow key triggers next song/media]
>^Left::Media_Prev [RControl key + Left arrow key triggers previous song/media]
>^Up::Volume_Up [RControl key + Up arrow key increases the volume]
>^Down::Volume_Down [RControl key + Down arrow key lowers the volume]
>^PgDn::Volume_Mute [RControl key + Page Down key mutes the volume]

Print Screen hotkey is used in conjunction with the FastStone Capture app. It's the app I use to easily capture screenshots on my desktop. Simply put, I open the FastStone Capture app first then use the print screen hotkey.

I used the Right Control key since it's one of my least used keys. More info on remapping keys can be found here. List of keys here.

How to run AutoHotkey?

autohotkey dash

1. Install and run AutoHotkey
2. Make script.ahk via Notepad
3. Copy my qabej.ahk code or make your own, Save as type > All Files and save with the file extension .ahk
autohotkey script save as ahk
4. Double-click your script or right-click > Run script

You can tell when your AutoHotKey script is running when you can see this little green H icon on your system tray:

autohotkey on system tray

How to make AutoHotkey script autorun on startup:

1. Create qabej.ahk shortcut via right-click > Create shortcut
2. Place shortcut on C:\Users\[username]\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup via %APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup in Windows Explorer or open Run app and type shell:startup

There are other hotkey programs out there but I find AutoHotkey simple and powerful to use. Their guide is easy to follow and it fulfills my basic needs. There are a lot of user made scripts online you can explore when you're feeling adventurous enough, or you can go all out in making your own complex scripts.

«