Created
February 3, 2025 08:38
-
-
Save numpde/48d6f44d22a35e391064a102d0b5afda to your computer and use it in GitHub Desktop.
Disables the power and sleep keys on the ROG Falchion keyboard via udev hwdb rules.
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
#!/bin/bash | |
set -e # Exit immediately on error | |
# Ensure script is run as root | |
if [[ $EUID -ne 0 ]]; then | |
echo "Error: This script must be run as root (use sudo)." >&2 | |
exit 1 | |
fi | |
echo "Detecting ROG Falchion keyboard..." | |
# Verify required commands are available | |
for cmd in udevadm systemd-hwdb tee; do | |
if ! command -v "$cmd" &>/dev/null; then | |
echo "Error: Required command '$cmd' not found." >&2 | |
exit 1 | |
fi | |
done | |
# Locate the keyboard device | |
DEVICE_PATH="/dev/input/by-id/usb-ASUSTeK_ROG_FALCHION-event-kbd" | |
if [[ ! -e "$DEVICE_PATH" ]]; then | |
echo "Error: ROG Falchion keyboard not detected. Ensure it is connected." >&2 | |
exit 1 | |
fi | |
# Extract vendor, product, and revision IDs | |
DEVICE_INFO=$(udevadm info "$DEVICE_PATH") | |
VENDOR_ID=$(echo "$DEVICE_INFO" | grep -oP 'ID_VENDOR_ID=\K[0-9a-f]+') | |
PRODUCT_ID=$(echo "$DEVICE_INFO" | grep -oP 'ID_MODEL_ID=\K[0-9a-f]+') | |
REVISION=$(echo "$DEVICE_INFO" | grep -oP 'ID_REVISION=\K[0-9a-f]+') | |
if [[ -z "$VENDOR_ID" || -z "$PRODUCT_ID" || -z "$REVISION" ]]; then | |
echo "Error: Failed to extract device identifiers." >&2 | |
exit 1 | |
fi | |
echo "Detected ROG Falchion - Vendor: $VENDOR_ID, Product: $PRODUCT_ID, Revision: $REVISION" | |
# Define hwdb file path | |
HWDB_FILE="/etc/udev/hwdb.d/99-asus-falchion.hwdb" | |
# Update hwdb rules | |
echo "Updating $HWDB_FILE..." | |
tee "$HWDB_FILE" > /dev/null <<EOF | |
evdev:input:b*v${VENDOR_ID}p${PRODUCT_ID}e${REVISION}* | |
KEYBOARD_KEY_10081=reserved | |
KEYBOARD_KEY_10082=reserved | |
EOF | |
# Apply the changes | |
echo "Applying udev rules..." | |
systemd-hwdb update | |
udevadm trigger | |
echo "Success! Power and sleep keys should now be disabled." | |
echo "You can test with: sudo evtest" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment