Add dedicated pen button detection test
User wants to test the 2 buttons on their Huion pen to see if they can be mapped to keyboard shortcuts (potentially replacing OTD). New script: test-pen-buttons.sh - Dedicated test for pen buttons only - Tests for xinput button events (button press N) - Tests for keyboard events (if pen buttons act like keyboard) - Clear instructions to hold pen in air (not touching tablet) - Separates pen buttons from tablet buttons - Shows how to remap based on button type detected The pen has 2 buttons on the side. They can be either: 1. xinput buttons (can remap with xbindkeys or xsetwacom) 2. keyboard events (already mapped to keys) This will determine if xsetwacom or xbindkeys is needed for pen button mapping.
+190 · 1 file changed
-
test-pen-buttons.sh+190 −0
@@ -0,0 +1,190 @@ +#!/bin/bash +# Dedicated pen button detection test + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +BOLD='\033[1m' +NC='\033[0m' + +echo "==========================================" +echo "Pen Button Detection Test" +echo "==========================================" +echo "" + +# Find pen device +PEN_ID=$(xinput list | grep -i "HUION.*Pen stylus" | grep -v "floating" | grep -o 'id=[0-9]*' | cut -d= -f2) + +if [ -z "$PEN_ID" ]; then + echo -e "${RED}ERROR: Pen device not found${NC}" + echo "" + echo "Make sure:" + echo " - Tablet is connected" + echo " - Native HID is enabled (OTD stopped)" + exit 1 +fi + +echo -e "${GREEN}Found: HUION Huion Tablet_G930L Pen stylus (id=$PEN_ID)${NC}" +echo "" + +echo "Your pen should have 2 buttons on the side." +echo "" +echo "We'll test for:" +echo " 1. xinput button events (button press N)" +echo " 2. Keyboard events (key press N)" +echo "" + +echo "==========================================" +echo "Test 1: xinput Button Events" +echo "==========================================" +echo "" +echo "Hold the pen in the air (NOT touching the tablet)" +echo "and press ONLY the pen buttons for 10 seconds." +echo "" +echo "Do NOT touch the pen to the tablet!" +echo "Do NOT press tablet buttons!" +echo "" +read -p "Press Enter to start, then press BOTH pen buttons repeatedly..." +echo "" + +PEN_OUTPUT=$(timeout 10 xinput test "$PEN_ID" 2>&1) + +echo "Raw output:" +echo "$PEN_OUTPUT" | head -30 +echo "" + +# Check for button events +if echo "$PEN_OUTPUT" | grep -q "button press"; then + echo -e "${GREEN}✓ Pen buttons detected as xinput buttons!${NC}" + echo "" + + # Extract button numbers + BUTTON_NUMBERS=$(echo "$PEN_OUTPUT" | grep "button press" | awk '{print $3}' | sort -n | uniq) + + echo "Pen button numbers:" + for btn in $BUTTON_NUMBERS; do + echo " Button $btn" + done + + echo "" + echo "These are xinput buttons that can be remapped!" + PEN_BUTTONS_TYPE="xinput" +else + echo -e "${YELLOW}⚠ No xinput button events detected${NC}" + echo "" + PEN_BUTTONS_TYPE="unknown" +fi + +echo "" +echo "==========================================" +echo "Test 2: Keyboard Events from Pen" +echo "==========================================" +echo "" + +# Check if pen buttons might be keyboard events +KEYBOARD_ID=$(xinput list | grep -i "HUION.*Tablet" | grep "keyboard" | grep -o 'id=[0-9]*' | cut -d= -f2) + +if [ -n "$KEYBOARD_ID" ]; then + echo "Testing if pen buttons send keyboard events..." + echo "Press ONLY the pen buttons for 5 seconds." + echo "" + read -p "Press Enter to start..." + echo "" + + KEYBOARD_OUTPUT=$(timeout 5 xinput test "$KEYBOARD_ID" 2>&1) + + if echo "$KEYBOARD_OUTPUT" | grep -q "key press"; then + echo -e "${GREEN}✓ Pen buttons send keyboard events!${NC}" + echo "" + + KEYCODES=$(echo "$KEYBOARD_OUTPUT" | grep "key press" | awk '{print $3}' | sort -n | uniq) + + echo "Keycodes detected:" + for keycode in $KEYCODES; do + KEYSYM=$(xmodmap -pke | grep "keycode *$keycode " | sed 's/.*= //' | awk '{print $1}') + if [ -n "$KEYSYM" ]; then + echo " Keycode $keycode = $KEYSYM" + else + echo " Keycode $keycode = (unknown)" + fi + done + + PEN_BUTTONS_TYPE="keyboard" + else + echo -e "${YELLOW}No keyboard events from pen buttons${NC}" + fi +fi + +echo "" +echo "==========================================" +echo "RESULTS & RECOMMENDATIONS" +echo "==========================================" +echo "" + +if [ "$PEN_BUTTONS_TYPE" = "xinput" ]; then + echo -e "${GREEN}✓ Pen buttons are xinput buttons${NC}" + echo "" + echo "Button numbers detected: $BUTTON_NUMBERS" + echo "" + echo "How to remap them:" + echo "" + echo "Option 1: xbindkeys (RECOMMENDED)" + echo " Create ~/.xbindkeysrc with:" + echo "" + for btn in $BUTTON_NUMBERS; do + echo " # Pen button $btn -> Ctrl+Z (undo)" + echo " \"xdotool key ctrl+z\"" + echo " b:$btn + Release" + echo "" + done + echo " Then run: xbindkeys" + echo "" + echo "Option 2: Test xsetwacom" + echo " Run: ./test-xsetwacom-compatibility.sh" + echo " If it works:" + for btn in $BUTTON_NUMBERS; do + echo " xsetwacom --set \"HUION Huion Tablet_G930L Pen stylus\" Button $btn \"key ctrl z\"" + done + echo "" + +elif [ "$PEN_BUTTONS_TYPE" = "keyboard" ]; then + echo -e "${GREEN}✓ Pen buttons send keyboard events${NC}" + echo "" + echo "Your pen buttons are already mapped to keys!" + echo "Use them directly in Paintstorm." + echo "" + echo "To remap to different keys:" + echo " Use xmodmap to remap the keycodes shown above" + echo "" + +else + echo -e "${YELLOW}⚠ Could not detect pen button events${NC}" + echo "" + echo "Possible reasons:" + echo " 1. You didn't press the pen buttons during the test" + echo " 2. Pen buttons require special configuration" + echo " 3. Pen buttons might not be functional" + echo "" + echo "Try again and make sure to:" + echo " - Hold pen in the air (not touching tablet)" + echo " - Press ONLY the pen buttons, NOT tablet buttons" + echo " - Press them multiple times during the test" + echo "" +fi + +echo "" +echo "==========================================" +echo "Quick Reference" +echo "==========================================" +echo "" +echo "Your Huion G930L has:" +echo " - 2 buttons on the pen" +echo " - 6 buttons on the tablet" +echo "" +echo "Tablet buttons: Already mapped to keyboard keys" +echo " Ctrl+Alt+Z, Ctrl+KP_Subtract, Ctrl+KP_Add," +echo " [, ], B, etc." +echo "" +echo "Pen buttons: Run this script again to detect them" +echo ""