From MEPIS Documentation Wiki
If you have special keys, buttons, or controls on your laptop or multimedia keyboard that you want to use, you have probably discovered that they don't work by default in MEPIS. However, they can be made to work.
How keyboards & controllers work
Before explaining how to fix them, it's important to understand how these keyboards and controls work.
- Whenever you press a key on the keyboard, a short numeric keycode is generated by the keyboard and sent to the OS.
- The code is mapped to a virtual key
- The virtual key performs whatever function is assigned to it in the OS -- i.e., printing a letter on the screen, or bringing up a certain program, etc.
So for example, when you press your left shift key, a keycode of "50" is sent to the OS. The OS has keycode "50" mapped to Shift_L, which the OS has been programmed to interpret in all the usual ways that a shift key is interpreted.
What you need to do to get your extra keys working is to tell MEPIS two things:
- What keys to map the keycodes from your extra keys or buttons to.
- What to do when the mapped keys are pressed.
Getting your keys working
First, open your system configuration and go to "Regional & Accessibility". Select "Keyboard Layout". Check "Enable keyboard layouts". Check the drop-down list to see if your model of keyboard is there. If so, select it and hit "apply".
If that doesn't work, install hotkey-setup from the repositories:
apt-get install hotkey-setup
It is designed to automatically determine your keyboard's model and set up the additional keys.
If that doesn't work, try installing hotkeys from the repositories:
apt-get install hotkeys
Hotkeys does not instantly work "out of the box". You will need to read the manual (type man:hotkeys in konqueror's address bar) and edit /etc/hotkeys.conf to tell hotkeys what model your keyboard is, and what programs or commands you want the extra buttons to perform. You will also need to set up hotkeys to run at login, which you can do with this command:
ln -s /usr/bin/hotkeys ~/.kde/Autostart/hotkeys
The manual way
As a last resort, you can manually set up your keyboard by finding the keycodes of the buttons, assigning them to virtual keys, and then setting up the virtual keys to perform tasks.
- Install xev from the repositories
apt-get install xev
- Run xev from the konsole
xev |grep keycode
- This will open a small window with a black square in it. Make sure the window is in focus and push the buttons on your keyboard. You should see entries coming up in your konsole window, something like this (this is for the 'a' key):
state 0x0, keycode 38 (keysym 0x61, a), same_screen YES,. For each button, write down the number listed after "keycode". In this case it would be '38'.
- Become root with "su".
- Create the file /etc/X11/Xmodmap and open it in an editor
touch /etc/X11/Xmodmap && kwrite /etc/X11/Xmodmap
- For each keycode, assign it to a nonexistant virtual key. The F-keys above F12 are good for this. It will look something like this:
keycode 132 = F13 keycode 133 = F14
- Now that you have done this, restart X by logging out and hitting ctrl-alt-backspace.
- At this point, your extra buttons will be seen by MEPIS as F13, F14, or whatever virtual keys you assigned. You can then assign these keys as hotkeys in KDE through normal means. For instance, if your keyboard has a "calculator" button which you have assigned to F13 and you want it to open kcalc; open the KDE menu editor, find the entry for kcalc, click "current shortcut key" and hit your calculator key. It would display as "F13".
Remapping the Windows keys
In this example, the left Windows key will be remapped to open KMenu. The bolded terms for the keycode and the command should be changed according to your particular situation.
1) use the xev command to find the keycode for your Windows key - for example, 133
2) use that keycode to create a ~/.kde/Autostart/win-key.sh script
#!/bin/bash xmodmap -e 'keycode 133 = Menu'
4) make the script executable with this command
chmod +x ~/.kde/Autostart/win-key.sh
5) reboot or manually run the win-key.sh script
6) run xev again to verify that "Menu" is now associated with the KeyPress and KeyRelease events for the Windows key
KeyPress event, serial 34, synthetic NO, window 0x4400001, root 0x189, subw 0x0, time 1334662, (-766,-31), root:(78,532), state 0x10, keycode 133 (keysym 0xff67, Menu), same_screen YES, XLookupString gives 0 bytes: XmbLookupString gives 0 bytes: XFilterEvent returns: False
KeyRelease event, serial 34, synthetic NO, window 0x4400001, root 0x189, subw 0x0, time 1334846, (-766,-31), root:(78,532), state 0x50, keycode 133 (keysym 0xff67, Menu), same_screen YES, XLookupString gives 0 bytes: XFilterEvent returns: False
7) goto KMenu > Settings > Regional & Accessibility > Keyboard Shortcuts > Shortcut Schemes tab > Global Shortcuts subtab.
8) Scroll down to the "Popup Launch Menu" shortcut under the Panel heading and double-click on it.
9) Click the "Alternate Shortcut" radio button (may need to click 'Advanced') and press the Windows key you want to remap.
10) After having pressed the Windows key the Alternate Shortcut will be now assigned to "Menu" which is assigned to your Windows key.
Pressing the Windows key should now bring up the KMenu, pressing it again (or ESC) should make KMenu disappear.