Title: lenovo n5901 xorg speical keys Subject: Setup Lenovo N5901 Wireless Keyboard for fluxbox By: John Stile Date: 20100602 ---------------------------------------- the simple xorg.conf keyboard is just this: Section "InputDevice" # generated from default Identifier "Keyboard0" Driver "kbd" EndSection Below are the steps to mapp the special keys Steps: 1. Use xev to determine what each special button click does 2. Edit ~/.fluxbox/keys to mapp keys to programs ---------------------------------------- Step 1: find what the keys do With xwindows urnning via fluxbox on tty1, run: xev > xev.20100602.txt In another terminal, tail -f xev.20100602.txt As click each button, note the output below: -----Orange Left KeyPress event, serial 34, synthetic NO, window 0x1400001, root 0x15d, subw 0x0, time 722181834, (-974,730), root:(514,748), state 0x0, keycode 152 (keysym 0x1008ff5d, XF86Explorer), same_screen YES, XLookupString gives 0 bytes: XmbLookupString gives 0 bytes: XFilterEvent returns: False KeyRelease event, serial 34, synthetic NO, window 0x1400001, root 0x15d, subw 0x0, time 722182018, (-974,730), root:(514,748), state 0x0, keycode 152 (keysym 0x1008ff5d, XF86Explorer), same_screen YES, XLookupString gives 0 bytes: XFilterEvent returns: False NOTE: keycode: 152 keysym: 0x1008ff5d, XF86Explorer -----Volume Down: KeyPress event, serial 34, synthetic NO, window 0x1400001, root 0x15d, subw 0x0, time 722204513, (-975,729), root:(513,747), state 0x0, keycode 122 (keysym 0x1008ff11, XF86AudioLowerVolume), same_screen YES, XLookupString gives 0 bytes: XmbLookupString gives 0 bytes: XFilterEvent returns: False KeyRelease event, serial 34, synthetic NO, window 0x1400001, root 0x15d, subw 0x0, time 722204681, (-975,729), root:(513,747), state 0x0, keycode 122 (keysym 0x1008ff11, XF86AudioLowerVolume), same_screen YES, XLookupString gives 0 bytes: XFilterEvent returns: False NOTE: keycode: 122 keysym: 0x1008ff11, XF86AudioLowerVolume -----Volume Up KeyPress event, serial 34, synthetic NO, window 0x1400001, root 0x15d, subw 0x0, time 722251632, (-982,730), root:(506,748), state 0x0, keycode 123 (keysym 0x1008ff13, XF86AudioRaiseVolume), same_screen YES, XLookupString gives 0 bytes: XmbLookupString gives 0 bytes: XFilterEvent returns: False NOTE: keycode: 123 keysym: 0x1008ff13, XF86AudioRaiseVolume KeyRelease event, serial 34, synthetic NO, window 0x1400001, root 0x15d, subw 0x0, time 722251816, (-982,730), root:(506,748), state 0x0, keycode 123 (keysym 0x1008ff13, XF86AudioRaiseVolume), same_screen YES, XLookupString gives 0 bytes: XFilterEvent returns: False NOTE: keycode: 123 keysym: 0x1008ff13, XF86AudioRaiseVolume -----Volume Mute KeyPress event, serial 34, synthetic NO, window 0x1400001, root 0x15d, subw 0x0, time 722266607, (-983,728), root:(505,746), state 0x0, keycode 121 (keysym 0x1008ff12, XF86AudioMute), same_screen YES, XLookupString gives 0 bytes: XmbLookupString gives 0 bytes: XFilterEvent returns: False KeyRelease event, serial 34, synthetic NO, window 0x1400001, root 0x15d, subw 0x0, time 722266815, (-983,728), root:(505,746), state 0x0, keycode 121 (keysym 0x1008ff12, XF86AudioMute), same_screen YES, XLookupString gives 0 bytes: XFilterEvent returns: False NOTE: keycode: 121 keysym: 0x1008ff12, XF86AudioMute -----Rewind KeyPress event, serial 34, synthetic NO, window 0x1400001, root 0x15d, subw 0x0, time 722279007, (-986,726), root:(502,744), state 0x0, keycode 173 (keysym 0x1008ff16, XF86AudioPrev), same_screen YES, XLookupString gives 0 bytes: XmbLookupString gives 0 bytes: XFilterEvent returns: False KeyRelease event, serial 34, synthetic NO, window 0x1400001, root 0x15d, subw 0x0, time 722279199, (-986,726), root:(502,744), state 0x0, keycode 173 (keysym 0x1008ff16, XF86AudioPrev), same_screen YES, XLookupString gives 0 bytes: XFilterEvent returns: False NOTE: keycode: 173 keysym: 0x1008ff16, XF86AudioPrev -----Stop KeyPress event, serial 34, synthetic NO, window 0x1400001, root 0x15d, subw 0x0, time 722298214, (-993,724), root:(495,742), state 0x0, keycode 174 (keysym 0x1008ff15, XF86AudioStop), same_screen YES, XLookupString gives 0 bytes: XmbLookupString gives 0 bytes: XFilterEvent returns: False KeyRelease event, serial 34, synthetic NO, window 0x1400001, root 0x15d, subw 0x0, time 722298382, (-993,724), root:(495,742), state 0x0, keycode 174 (keysym 0x1008ff15, XF86AudioStop), same_screen YES, XLookupString gives 0 bytes: XFilterEvent returns: False NOTE: keycode: 174 keysym: 0x1008ff15, XF86AudioStop -----Play KeyPress event, serial 34, synthetic NO, window 0x1400001, root 0x15d, subw 0x0, time 722314222, (-997,722), root:(491,740), state 0x0, keycode 172 (keysym 0x1008ff14, XF86AudioPlay), same_screen YES, XLookupString gives 0 bytes: XmbLookupString gives 0 bytes: XFilterEvent returns: False KeyRelease event, serial 34, synthetic NO, window 0x1400001, root 0x15d, subw 0x0, time 722314406, (-997,722), root:(491,740), state 0x0, keycode 172 (keysym 0x1008ff14, XF86AudioPlay), same_screen YES, XLookupString gives 0 bytes: XFilterEvent returns: False NOTE: keycode: 172 keysym: 0x1008ff14, XF86AudioPlay -----Forward KeyPress event, serial 34, synthetic NO, window 0x1400001, root 0x15d, subw 0x0, time 722326278, (-999,718), root:(489,736), state 0x0, keycode 171 (keysym 0x1008ff17, XF86AudioNext), same_screen YES, XLookupString gives 0 bytes: XmbLookupString gives 0 bytes: XFilterEvent returns: False KeyRelease event, serial 34, synthetic NO, window 0x1400001, root 0x15d, subw 0x0, time 722326406, (-999,718), root:(489,736), state 0x0, keycode 171 (keysym 0x1008ff17, XF86AudioNext), same_screen YES, XLookupString gives 0 bytes: XFilterEvent returns: False NOTE: keycode: 171 keysym: 0x1008ff17, XF86AudioNext ----Windows Key KeyPress event, serial 35, synthetic NO, window 0x1400001, root 0x15d, subw 0x0, time 722423522, (-1007,718), root:(481,736), state 0x0, keycode 133 (keysym 0xffeb, Super_L), same_screen YES, XLookupString gives 0 bytes: XmbLookupString gives 0 bytes: XFilterEvent returns: False KeyRelease event, serial 35, synthetic NO, window 0x1400001, root 0x15d, subw 0x0, time 722423658, (-1007,718), root:(481,736), state 0x40, keycode 133 (keysym 0xffeb, Super_L), same_screen YES, XLookupString gives 0 bytes: XFilterEvent returns: False NOTE: keycode: 133 keysym: 0xffeb, Super_L -------------------------------- Step 2. Setup our mapping Normal X uses xmodemap to mapp the keys to some program When x starts, /etc/X11/xdm/Xsession and /etc/X11/xinit/xinitrc run "xmodmap ${HOME}/.Xmodmap" Fluxbox has a cool file that does this easier, I think. # # Our The Map: # Orange Button: keycode:152 keysym:0x1008ff5d,XF86Explorer ------------------------------------------------------------- Volume Down: keycode:122 keysym:0x1008ff11,XF86AudioLowerVolume Volume Up keycode:123 keysym:0x1008ff13,XF86AudioRaiseVolume Volume Mute keycode:121 keysym:0x1008ff12,XF86AudioMute ------------------------------------------------------------- Rewind keycode:173 keysym:0x1008ff16,XF86AudioPrev Stop keycode:174 keysym:0x1008ff15,XF86AudioStop Play keycode:172 keysym:0x1008ff14,XF86AudioPlay Forward keycode:171 keysym:0x1008ff17,XF86AudioNext ------------------------------------------------------------- Windows Key keycode:133 keysym: 0xffeb, Super_L # # After updating the "$HOME/.fluxbox/keys", you don't have to restart. # Just run "Reload Config" from the fluxbox menu # # # Mapp Volume Up/Down/Mute (simple example) # cat >> "$HOME/.fluxbox/keys" <<'END_KEYS' XF86AudioLowerVolume :Exec amixer -q set PCM 5%- XF86AudioRaiseVolume :Exec amixer -q set PCM 5%+ XF86AudioMute :Exec amixer set PCM togglel END_KEYS # # Mapp orange Button to run firefox (more complicated) # Uses a script to use current running, or launch new. # Firefox hates running two copies, so this avoids that # REFERENCE: http://fluxbox-wiki.org/index.php/Keyboard_shortcuts # cat >> "$HOME/.fluxbox/keys" <<'END_KEYS' XF86Explorer :ExecCommand ~/bin/find_app.sh /usr/bin/firefox-bin END_KEYS Now create the sciprt cat >> "$HOME/bin/find_app.sh <<'END_find_app.sh' #!/bin/bash # Find_app # Author: Lucas van Staden (lvs at dedmeet.com / www.dedmeet.com) # This little script will try and find the application attempting to start # in the running processes, and if found, focus the application # if not found, a new instance will start # usage: # find_app.sh # params # 1 - application to start (full path) # helper applications WMCTRL=`which wmctrl`; GREP=`which grep`; APPLICATION=$1; BASENAME=`basename $APPLICATION`; BASENAME=`echo $BASENAME | tr "[:upper:]" "[:lower:]"` FOUND=0; function findwindow { # 1 = BASENAME # 2 = WMCTRL # 3 = GREP IFS=$'\n'; for RUNNING in `$2 -l -x` do if [ `echo $RUNNING | tr "[:upper:]" "[:lower:]" | $3 -c $1` -gt 0 ] then HOSTNAME=`hostname` WINDOW=${RUNNING#*${HOSTNAME} } $2 -a $WINDOW FOUND=1; fi; done } findwindow $BASENAME $WMCTRL $GREP; if [ $FOUND -eq 0 ] then $APPLICATION & sleep 2; # Try and find the application, after opened findwindow $BASENAME $WMCTRL $GREP; if [ $FOUND -eq 0 ] then # Still not found, wait a bit more, and try again sleep 3; findwindow $BASENAME $WMCTRL $GREP; fi fi END_find_app.sh # # Still working on this one. # Mapp Play/Stop/Rew/FF to currently focused application # REFERENCE: http://cweiske.de/howto/xmodmap/allinone.html#tips.play # # I mostly use this machine for Music Player Daemon (mpd) # So right now I have the keys mapped to mpc # cat >> "$HOME/.fluxbox/keys" <<'END_KEYS' XF86AudioNext :ExecCommand mpc next XF86AudioPlay :ExecCommand mpc toggle XF86AudioStop :ExecCommand mpc stop XF86AudioPrev :ExecCommand mpc prev END_KEYS