Tuesday, December 23, 2008

Remapping Menu key as Fn key

Info from following urls:
  http://humbledown.org/files/dunlug-keyboard-remap.pdf
  http://www.chuug.org/talks/tricks1a.pdf
  http://ubuntuforums.org/archive/index.php/t-820187.html
  http://www.linuxquestions.org/questions/linux-newbie-8/remapping-keys-using-xmodmap-home-key-652268/
  http://vim.wikia.com/wiki/Remap_the_Escape_key

    As mentioned in my previous post, I was trying to remap the Menu key as a Fn key. Well, I managed to do it, but it only works with the navigation keys. Eg.: Fn+Left=Home, Menu+Left=Home, Fn+Ins=PrtSc but Menu+Ins=nothing

    The command xmodmap was used to remap the Menu key as Mode_switch and the key mappings for the navigation keys were edited as well. A useful commandline utility I found was xev. It prints out the events in the X display system. Press Ctrl-Alt-T to open the terminal console and run "xev". If you press the Left key, you can see the keycode as 100 and the keysymname as Left. Now try with Fn+Left. Surprisingly, Fn has no keycode unlike the other modifier keys (Ctrl,Alt,Shift). Click in the terminal window and press Ctrl-C to exit. Now for xmodmap.

    Steps:
  1. Press Ctrl-Alt-T to open the terminal console.

  2. Type "sudo kwrite /usr/bin/remap-keys" to create a new bash script.

  3. Copy and paste the following into KWrite:

    #!/bin/bash

    # remap Menu key as a mode switch, like Fn
    # Need to remap Menu + up/down/left/right also
    # run xev to see info on each key pressed

    xmodmap -e "keycode 117 = Mode_switch"

    # = byItself withShift withModeSwitch
    xmodmap -e "keycode 100 = Left NoSymbol Home"
    xmodmap -e "keycode 102 = Right NoSymbol End"
    xmodmap -e "keycode 98 = Up NoSymbol Prior"
    xmodmap -e "keycode 104 = Down NoSymbol Next"

    xset -r 117 # Prevent the Menu key from autorepeating

  4. Save the file and exit back to the terminal console.

  5. Set the permissions to execute it by typing "sudo chmod 755 /usr/bin/remap-keys"

  6. Type "remap-keys" to run it. Use xev to test or try scrolling a document or webpage.

    If you wish to run it at startup, the fastest way would be to add "source /usr/bin/remap-keys" to the end of your .bashrc (see post on "Using Aliases to Make Life Easier").

    Keycode 117 is the keycode for the Menu key, gotten from running xev. Keycode 100 is the keycode for the Left key. The remapping "= Left NoSymbol Home" means when the Left key is pressed by itself, it means Left, Shift+Left=nothing, Mode_switch+Left=Home (in this case, Menu is our new Mode_switch key)

(^ v ^)

No comments: