Author Topic: HOW TO: Application-specific key mapping  (Read 2922 times)

eviLjazz

  • Full Member
  • ***
  • Posts: 116
    • View Profile
    • http://katastrophos.net/andre/blog
HOW TO: Application-specific key mapping
« on: June 07, 2004, 12:10:17 am »
Hi everybody,

just finished a small launcher script. It will load a custom xmodmap keymap if available, start the application and reset the keymap if the app quits.

Code: [Select]
#!/bin/bash



KBMODDIR=/etc/X11/kb

DEFAULT=$KBMODDIR/corgi.xmodmap



USERFILE=$KBMODDIR/$1.xmodmap



CUSTOMKEYMAP=0



if [ -e $USERFILE ]; then

    echo "using available custom keymap $USERFILE"

    xmodmap $USERFILE

    CUSTOMKEYMAP=1

fi



$1 $2 $3 $4 $5 $6 $7 $8 $9



if [ $CUSTOMKEYMAP -eq 1 ]; then

    echo "resetting keymap"

    xmodmap $DEFAULT

fi


Just name it launch, put it into /usr/local/bin and make it executable via chmod 755 /usr/local/bin/launch.
It will look into /etc/X11/kb for application-specific keymaps.
For example, if I wanted to launch gqview I would start it by
launch gqview

The script would look into /etc/X11/kb for a file named gqview.xmodmap.
If it\'s found it will be loaded.

Here is the gqview.xmodmap example:
Code: [Select]
! map scrollwheel up/right to "next picture"

keycode 134 = n



! map scrollwheel down/left to "previous picture"

keycode 133 = b



!map Cancel side-button to "Fullscreen"

keycode 132 = f



!map OK side-button to "Rotate clockwise"

keycode 131 = bracketleft


Just put this file into /etc/X11/kb/

In order to start gqview with this keymapping each time, one would have to change the line
   Exec=gqview
to
   Exec=launch gqview
in the file
/usr/share/applications/gqview.desktop

You can adjust other applications links accordingly.

You\'ll need to restart either matchbox or the whole X11. Simplest way is pressing CTRL-ALT-Backspace and just restarting the X11 Server via startx.

Please note, that this keymapping is still global for the whole X11 server, so every other application will also have the same key maps. But I think, it\'s still a decent way.

I hope this is usefull to somebody.
Regards,
evilJazz
Sharp Zaurus SL-C3200/36GB running Cacko : Fujitsu LifeBook U2010/64GB SSD running Win7 : Nokia N900 (yes, flame me.) Blog : Twitter : Trac
Quasar Media Player : QScrobbler : Enhanced audio driver and mixer for C1000/C3x00 : Unified Sharp/Tetsu/Cacko/pdaXrom Kernel 2.4.20 branch : My packages : Sources

eviLjazz

  • Full Member
  • ***
  • Posts: 116
    • View Profile
    • http://katastrophos.net/andre/blog
HOW TO: Application-specific key mapping
« Reply #1 on: June 07, 2004, 01:18:18 am »
here is my xmms.xmodmap:
Code: [Select]
! map scrollwheel up/right to "next song"

keycode 134 = b



! map scrollwheel down/left to "previous song"

keycode 133 = z



!map Cancel side-button to "Pause"

keycode 132 = c



!map OK side-button to "Play"

keycode 131 = x
Sharp Zaurus SL-C3200/36GB running Cacko : Fujitsu LifeBook U2010/64GB SSD running Win7 : Nokia N900 (yes, flame me.) Blog : Twitter : Trac
Quasar Media Player : QScrobbler : Enhanced audio driver and mixer for C1000/C3x00 : Unified Sharp/Tetsu/Cacko/pdaXrom Kernel 2.4.20 branch : My packages : Sources