Last active
January 3, 2025 23:26
-
-
Save Ultra980/512c17b7f067a0ea0d3e852ec3528b14 to your computer and use it in GitHub Desktop.
A script to run certain commands when pressing a hotkey on ASUS laptop keyboards.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# asus-hotkey-run - a script to run events on hotkey presses from ASUS laptops | |
# This is configured for the 2019 Zenbook Pro Duo, you should change this for your own laptop. | |
# (by hotkeys I mean those next to the power button, not fn+Fx) | |
# Huge thanks to OpenAI's ChatGPT, for writing most of this code :) | |
# The conversation that helped me write this script: https://chat.openai.com/share/c4a1915f-a90e-4357-b173-9be733ba3b10 | |
set -eu # We can't set `-o pipefail` because the evtest command that gets the device always fails | |
# Find the hotkey device | |
device="$(echo | evtest 2>&1 | grep -i "hotkeys" | cut -d':' -f1)" | |
# The scancodes for the keys. Find them with `sudo evtest <device here>`, followed by pressing them. | |
scancode1=9c | |
scancode2=9d | |
scancode3=6a | |
# if your laptop has more or less hotkeys, add or remove them here and change the awk syntax accordingly. | |
evtest "$device" | awk ' | |
/MSC_SCAN/ { scan = $NF } | |
/value/ { | |
if ($NF == "9d") { | |
system("playerctl previous") | |
} else if ($NF == "9c") { | |
system("playerctl play-pause") | |
} else if ($NF == "6a") { | |
system("playerctl next") | |
} | |
} | |
' |
Huge thanks to ChatGPT for this :)
https://chat.openai.com/share/c4a1915f-a90e-4357-b173-9be733ba3b10
(the conversation also includes how I figured out the scancodes of my keys)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A script to run certain commands when pressing a hotkey on ASUS keyboards. You need to change it for your own laptop, I'm not sure it works for anything other than mine. Instructions in the comments of the code.