Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Hardware
User Name
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?


  Search this Thread
Old 10-05-2007, 12:11 PM   #1
LQ Newbie
Registered: Nov 2003
Location: Sweden
Distribution: Slackware
Posts: 27

Rep: Reputation: 16
Add a new modifier key

Got Compiz Fusion up and running today, sweet. Now I'm planning to dedicate the Caps Lock key to window management, thus turning it to a modifier key.

"Wait a minute", you say, "this has been answered like 10000 times before if not more!" And you are right, I apologize for brining such a common "trick"/question up again; I've search for a while, both here and using Google, but still haven't found a solution.

So what's the problem?

I don't want to switch keys or remap caps lock to an existing key. I want a new modifier key. Obviously, xmodmap is the answer. I ran it and got

hans@localhost:~$ xmodmap
xmodmap:  up to 3 keys per modifier, (keycodes in parentheses):

shift       Shift_L (0x32),  Shift_R (0x3e)
control     Control_L (0x25),  Control_R (0x6d)
mod1        Alt_L (0x40),  Alt_L (0x7d),  Meta_L (0x9c)
mod2        Num_Lock (0x4d)
mod4        Super_L (0x7f),  Hyper_L (0x80)
mod5        Mode_switch (0x5d),  ISO_Level3_Shift (0x71),  ISO_Level3_Shift (0x7c)
After searching a while, I found Hyper_L. Using xev, I learned that the keycode of my caps lock key was 66.

xmodmap -e 'remove lock = Caps_Lock'
xmodmap -e 'keycode 66 = Hyper_L'
xmodmap -e 'add mod3 = Hyper_L'
Sure enough, when running xev again, it says keycode 66 (keysym 0xffed, Hyper_L). So far so good.

So why are you asking for help then?

Because, apparently, my applications don't like the new key. When trying to map a shortcut in KDE applications, it simply doesn't react when I press the caps lock key (which should have shown as "Hyper").

Better luck with CompizConfig Settings Manager (K version) then? Kind of. I can map actions to "Hyper+something", but when I press the combination, nothing happens.

That's how far I've gotten. It feels like I've made a stupid mistake somewhere, instead of trying for hours and finally realizing it I beg for your help instead.

If the Hyper key isn't any good, I've thought of another possible solution: map caps lock to <Control><Super><Shift><Alt>. Is that possible? So when I press the caps key, it's like pressing the four modifier keys, creating a "new" modifier key.

As always, thanks in advance.
Old 10-06-2007, 05:51 AM   #2
LQ Guru
Registered: Jan 2002
Posts: 6,042

Rep: Reputation: Disabled
I think X Window System uses its own keymap which may change what you set in bash. If you are using Xorg 7.x, you can use custom key code option in your /etc/X11/xorg.conf file. Also you can place a file in your home directory, so KDE runs it when you log into it. I think KDM, a display manager, also provides a way to set custom key maps. Probably the xorg.conf way will be the best way.

I do not use KDE because it is too bloated, so check its documentation or ask a KDE developer.

Just remember, what you set in virtual terminal will not work for other programs. Every virtual terminal and every program that you run gets its own environment. Linux is a multi-task OS which means it runs many tasks with the same default environment that is separated by other programs.
Old 10-06-2007, 03:38 PM   #3
LQ Newbie
Registered: Nov 2003
Location: Sweden
Distribution: Slackware
Posts: 27

Original Poster
Rep: Reputation: 16
Originally Posted by Electro View Post
I think X Window System uses its own keymap which may change what you set in bash. If you are using Xorg 7.x, you can use custom key code option in your /etc/X11/xorg.conf file.
Didn't find much info about it, do you know where I can find more (as in more relevant) information?

Originally Posted by Electro View Post
Just remember, what you set in virtual terminal will not work for other programs.
Is that really the case with xmodmap? Because I have no problems remapping caps lock to other keys, such as escape.

Right now I wonder if it isn't a KDE issue; Hyper isn't listed as a modifier key under "KDE Modifiers". Does anyone know how to add it there?
Old 06-25-2009, 12:59 PM   #4
LQ Newbie
Registered: Jun 2009
Posts: 6

Rep: Reputation: Disabled
I would also like to know this.
Old 03-20-2011, 02:33 AM   #5
LQ Newbie
Registered: Dec 2007
Posts: 13

Rep: Reputation: 0
how to add a modifier

This is an excerpt from the Xmodmap man page in Ubuntu and might be the clue of how to do this:
This removes all entries in the modifier map for the given
modifier, where valid name are: Shift, Lock, Control, Mod1,
Mod2, Mod3, Mod4, and Mod5 (case does not matter in modifier
names, although it does matter for all other names). For
example, ‘‘clear Lock’’ will remove all any keys that were
bound to the shift lock modifier.

This adds all keys containing the given keysyms to the
indicated modifier map. The keysym names are evaluated after
all input expressions are read to make it easy to write
expressions to swap keys (see the EXAMPLES section).

This removes all keys containing the given keysyms from the
indicated modifier map. Unlike add, the keysym names are
evaluated as the line is read in. This allows you to remove
keys from a modifier without having to worry about whether or
not they have been reassigned.
Old 03-21-2011, 06:04 AM   #6
Senior Member
Registered: Nov 2003
Location: London, England
Distribution: Ubuntu
Posts: 1,460

Rep: Reputation: 47
I think you've missed a few steps. I haven't messed around with hotkeys lately, but when I wanted to add a key on Debian Lenny, the full process I used was:

Use xev to find the keycode, which was in this case the standard 115

Edit /usr/share/X11/XKeysymDB so it knows there's a new key for it to deal with on the keyboard:
Start :11000001
added to the end of the file

Create the file /etc/X11/Xmodmap to link the Start key to keycode 115:
keycode 115 = Start

To get xmodmap to actually load the file you just created, near the end of the file /etc/X11/Xsession add:
[ -f /etc/X11/Xmodmap ] && xmodmap /etc/X11/Xmodmap

Hope something in that helps!


caps, keyboard, keys, lock, xmodmap

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
X Utility to lock a modifier key down manually? enigma_0Z Linux - Desktop 0 10-05-2007 10:13 AM
XKeyEvent and the mode_switch (AltGr) modifier LonelyStar Programming 1 10-04-2007 01:35 PM
Win / Tux key no longer bound as a modifier in KDE 3.5 / FC 4 atarisan Linux - General 6 02-23-2006 05:24 PM
ssh-add key for windows hamish Linux - Networking 4 01-13-2005 07:43 PM
how to add PGP key to GnuPG or PGPKeyring " zameer_india Linux - Software 3 10-05-2004 11:21 PM > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 04:13 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration