Remapping an arbitrary combo to ALT TAB in (L)Ubuntu

My laptop has a missing Tab key. This has led me to some [interesting workarounds], but I could never quite get the keyboard's behavior back to what it once was with these hackish solutions.

I installed Lubuntu in dual boot with Windows 7 a few weeks ago. Lubuntu comes with Openbox, a customizable and lightweight window manager. I didn't feel like rewriting Keymapper for Linux since it relies on low-level hooks so I turned to Google in search for an alternative. I quickly discovered that it's possible to use some of the already-installed tools to accomplish what I needed.

One such tool is Xmodmap. It lets you configure a mapping for a given pair of keys. In order to figure out the key codes I needed, I used xev, yet another utility whose purpose is to open a small window and print events on the terminal as they happen.

Let's say you want to remap 1 (& on an azerty keyboard) to tab. Running xev and pressing 1 while the xev window is on focus produces the following output :

KeyPress event, serial 48, synthetic NO, window 0x2400001,
  root 0x7e, subw 0x0, time 25309279, (168,-12), root:(169,14),
  state 0x0, keycode 10 (keysym 0x26, ampersand), same_screen YES,
  XLookupString gives 1 bytes: (26) "&"
  XmbLookupString gives 1 bytes: (26) "&"
  XFilterEvent returns: False

 KeyRelease event, serial 48, synthetic NO, window 0x2400001,
  root 0x7e, subw 0x0, time 25309358, (168,-12), root:(169,14),
  state 0x0, keycode 10 (keysym 0x26, ampersand), same_screen YES,
  XLookupString gives 1 bytes: (26) "&"
  XFilterEvent returns: False

From this, we can conclude that the keycode "10" corresponds to the "1" key. Remapping it to Tab can then be achieved by running the command xmodmap -e "keycode 10 = Tab"

This method worked for Tab and Ctrl Tab, but not for Alt Tab. I did some more googling but I couldn't find a satisfying result. I eventually found the answer in a website I no longer have the link to. It turns out that Openbox lets you define custom shortcuts for various tasks via an xml file inside ~/.config/openbox. The file is called lubuntu-rc on Lubuntu, so I modified that. A quick search for A-Tab revealed the following :

    <keybind key="A-Tab">
      <action name="NextWindow">
        <dialog>icons</dialog>
        <finalactions>
          <action name="Focus"/>
          <action name="Raise"/>
          <action name="Unshade"/>
        </finalactions>
      </action>
    </keybind>
    <keybind key="A-S-Tab">
      <action name="PreviousWindow">
        <finalactions>
          <action name="Focus"/>
          <action name="Raise"/>
          <action name="Unshade"/>
        </finalactions>
      </action>
    </keybind>

All I had to do was to duplicate the above XML code and replace A-Tab with A-0x31 for it to work. For the record, 0x31 is the key that's right above Tab on my keyboard. Restarting Openbox with the openbox --restart command was enough for the changes to take effect. I was then able to use Alt Tab, a feat that was out of my reach until that point.

You might wonder how I was able to survive on Windows without the beloved Alt Tab shortcut. And the answer is that I substituted its functionality with the Windows + [n] shortcut, [n] being the nth application in the taskbar. I could have searched for a solution but this workaround was flexible enough for me so I stuck with it.

Commentaires

Posts les plus consultés de ce blog

Writing a fast(er) youtube downloader

Decrypting .eslock files

My experience with Win by Inwi