Last active
June 19, 2023 09:49
-
-
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 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 | |
# set -x # debug | |
# 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 | |
sudoers_configured=1 # Change this to 0 if you don't have sudoers configured to allow running evtest without a password as your user. | |
# Check if the script has root privileges | |
if [[ $EUID -ne 0 && $sudoers_configured -ne 1 ]]; then | |
echo "This script requires root privileges." | |
exit 1 | |
fi | |
device=/dev/input/event7 # Find it with `sudo evtest` - it should be named something like "ASUS WMI Hotkeys" | |
# 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. | |
sudo 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.