MTek K371 Power and Office keys under Linux
Tuesday, May 18th, 2004
I’ve got this MTek K371L mini-ergonomical keyboard. It’s got 7 buttons on the top of the keyboard for automatic copy-pasting, opening files, etc. They simultate Control-O and those kind of keybindings. These are pretty Windows specific, so I always thought I couldn’t use them under Linux. On the top right of the keyboard are three other buttons: Wake, Sleep and Power. Thought I couldn’t use them either under Linux. Turns out I was wrong.
Wake / Sleep / Power keys
The three powermanagement keys give off normal key scancodes and are already bound to couple of keycodes:
- Wake: keycode: 227
- Sleep: keycode: 223
- Power:keycode: 222
If you add the following lines to a file and run the file using the command xmodmap [FILENAME]
, you’ll be able to use them in most X programs by just using some ‘Capture key’ option or by entering the keyname. Here’s the lines to add to the file:
keycode 222 = XF86PowerOff
keycode 223 = XF86Standby
keycode 227 = XF86WakeUp
Don’t worry, they won’t actually do what the keynames suggest. I’ve got the ‘Power’ key bound to my terminal locking script (using xtrlock).
Office keys
Getting the office keys to do what I want was a little tougher. Of course they already work like normal Control-O, Control-S, etc keys, but that’s not what I want to do with them. I wanted to use them to turn up and down the volume and that kind of stuff.
Turns out that those keys actually simulate the RIGHT control (Control_R) instead of the LEFT. Since I Never Ever use the RIGHT control key, I could easily rebind them to do whatever I wanted. Since I wanted each key to do something different, I had to add another modifier to the key. Not the default Control modifier, but some empty one. Here’s how you can rebind the keys. Please note that your right control key won’t work anymore if you do this:
- Find an empty modifier key. These differ on each platform it seams, so you’ll have to check for yourself which modifier is unused. I used the xkeycaps program to check out all keys on my keyboard to see what modifier was free. Turns out both mod2 and mod5 were unused. I went for Mod5 because I haven’t ever seen this modifier used before.
- Next, remove the right control key from the Control modifier list by adding this line to the xmodmap file:
remove Control = Control_R
. - Now, add the right control key to the empty modifier by adding another line to the modmap file. In my case Mod5:
add Mod5 = Control_R
. - You can now bind actions to the office keys at the top of the keyboard because they emulate Control_R plus some key. Since Control_R is now Mod5, programs will understand the key and you can actually use it. It’s the same as with the last step in the Wake/Sleep/Power keys section above.
I ended up with the following modmap file named: ~/.xkeys:
keycode 222 = XF86PowerOff
keycode 223 = XF86Standby
keycode 227 = XF86WakeUp
remove Control = Control_R
add Mod5 = Control_R
I now have the Office keys mapped (using WindowMaker’s Menu which allows me to bind key shortcuts to menu items) to Volume Up/Down, XMMS Next, Previous, Stop, Play, etc. I use aumix’s commandline options to set the volume higher and lower and XMMS’s commandline options to control XMMS. Pretty cool.
I’ve also added this little tip to the Tips and Tricks page under the X11 section.