Why do my xmodmap binds involving AltGr only work on some keys?
Clash Royale CLAN TAG#URR8PPP
up vote
10
down vote
favorite
I want to remap my AltGR+Right_Windows but I can't figure out how. No matter what I try, pressing the right windows key emits the name keysym when right alt is pressed or not.
These are the contents of the xmodmap file I am testing right now. In my keyboard, 38 is the keycode for "a", 48 is the keycode for aportrophe/doublequote and 134 is the keycode for the right windows key.
keycode 38 = 1 2 3 4 5 6 7 8
keycode 48 = 1 2 3 4 5 6 7 8
keycode 134 = 1 2 3 4 5 6 7 8
When I press Right_Alt+apostrophe, it outputs 5 but Right_Alt+a and Right_Alt+Right_Windows give 1 (both when right alt is pressed and when it isn't) which is not what I wanted.
My current keyboard layout is us(alt-intl)
and the right alt is apparently set up to act as AltGr / Iso_Level3_Shift. The output of xmodmap -pm
is the following:
xmodmap: up to 4 keys per modifier, (keycodes in parentheses):
shift Shift_L (0x32), Shift_R (0x3e)
lock Caps_Lock (0x42)
control Control_L (0x25), Control_R (0x69)
mod1 Alt_L (0x40), Meta_L (0xcd)
mod2 Num_Lock (0x4d)
mod3
mod4 Super_L (0x85), Super_R (0x86), Super_L (0xce), Hyper_L (0xcf)
mod5 ISO_Level3_Shift (0x5c), Mode_switch (0xcb)
xmodmap
add a comment |Â
up vote
10
down vote
favorite
I want to remap my AltGR+Right_Windows but I can't figure out how. No matter what I try, pressing the right windows key emits the name keysym when right alt is pressed or not.
These are the contents of the xmodmap file I am testing right now. In my keyboard, 38 is the keycode for "a", 48 is the keycode for aportrophe/doublequote and 134 is the keycode for the right windows key.
keycode 38 = 1 2 3 4 5 6 7 8
keycode 48 = 1 2 3 4 5 6 7 8
keycode 134 = 1 2 3 4 5 6 7 8
When I press Right_Alt+apostrophe, it outputs 5 but Right_Alt+a and Right_Alt+Right_Windows give 1 (both when right alt is pressed and when it isn't) which is not what I wanted.
My current keyboard layout is us(alt-intl)
and the right alt is apparently set up to act as AltGr / Iso_Level3_Shift. The output of xmodmap -pm
is the following:
xmodmap: up to 4 keys per modifier, (keycodes in parentheses):
shift Shift_L (0x32), Shift_R (0x3e)
lock Caps_Lock (0x42)
control Control_L (0x25), Control_R (0x69)
mod1 Alt_L (0x40), Meta_L (0xcd)
mod2 Num_Lock (0x4d)
mod3
mod4 Super_L (0x85), Super_R (0x86), Super_L (0xce), Hyper_L (0xcf)
mod5 ISO_Level3_Shift (0x5c), Mode_switch (0xcb)
xmodmap
No idea exactly what's going on, but if you haven't done so already, you might want to runxev
and press the various key combinations to see if the hardware and up to the Xwindows level is getting distinguishable keypresses to start with.
â Joe
Dec 18 '15 at 23:46
I'm experiencing the very same issue. I wanted to modify comma and dot to also support printing czech and english double quotes (âÂÂ/âÂÂ/âÂÂ) that I have to write using compose key otherwise. I'm usingus(cz_sk_de)
keyboard layout and xmodmap.
â Pavel à  imerda
Aug 6 '16 at 9:13
So what now? It's not practical to waste another bounty nor to start a new question when this one pretty well describes the issue. It looks like a bug in xorg but I haven't found any references. The existing answer is clearly wrong despite being automaticaly awarded.
â Pavel à  imerda
Sep 5 '16 at 16:26
I ended giving up and use different keybinds that I know work :/ I agree that this does look like a bug but I don' t know what system its related to and where to report it...
â hugomg
Sep 5 '16 at 17:20
I found some information here... blog.azundris.com/archives/193-X-treme-pain-XKB-vs-XModMap.html
â Pavel à  imerda
Oct 1 '16 at 20:20
add a comment |Â
up vote
10
down vote
favorite
up vote
10
down vote
favorite
I want to remap my AltGR+Right_Windows but I can't figure out how. No matter what I try, pressing the right windows key emits the name keysym when right alt is pressed or not.
These are the contents of the xmodmap file I am testing right now. In my keyboard, 38 is the keycode for "a", 48 is the keycode for aportrophe/doublequote and 134 is the keycode for the right windows key.
keycode 38 = 1 2 3 4 5 6 7 8
keycode 48 = 1 2 3 4 5 6 7 8
keycode 134 = 1 2 3 4 5 6 7 8
When I press Right_Alt+apostrophe, it outputs 5 but Right_Alt+a and Right_Alt+Right_Windows give 1 (both when right alt is pressed and when it isn't) which is not what I wanted.
My current keyboard layout is us(alt-intl)
and the right alt is apparently set up to act as AltGr / Iso_Level3_Shift. The output of xmodmap -pm
is the following:
xmodmap: up to 4 keys per modifier, (keycodes in parentheses):
shift Shift_L (0x32), Shift_R (0x3e)
lock Caps_Lock (0x42)
control Control_L (0x25), Control_R (0x69)
mod1 Alt_L (0x40), Meta_L (0xcd)
mod2 Num_Lock (0x4d)
mod3
mod4 Super_L (0x85), Super_R (0x86), Super_L (0xce), Hyper_L (0xcf)
mod5 ISO_Level3_Shift (0x5c), Mode_switch (0xcb)
xmodmap
I want to remap my AltGR+Right_Windows but I can't figure out how. No matter what I try, pressing the right windows key emits the name keysym when right alt is pressed or not.
These are the contents of the xmodmap file I am testing right now. In my keyboard, 38 is the keycode for "a", 48 is the keycode for aportrophe/doublequote and 134 is the keycode for the right windows key.
keycode 38 = 1 2 3 4 5 6 7 8
keycode 48 = 1 2 3 4 5 6 7 8
keycode 134 = 1 2 3 4 5 6 7 8
When I press Right_Alt+apostrophe, it outputs 5 but Right_Alt+a and Right_Alt+Right_Windows give 1 (both when right alt is pressed and when it isn't) which is not what I wanted.
My current keyboard layout is us(alt-intl)
and the right alt is apparently set up to act as AltGr / Iso_Level3_Shift. The output of xmodmap -pm
is the following:
xmodmap: up to 4 keys per modifier, (keycodes in parentheses):
shift Shift_L (0x32), Shift_R (0x3e)
lock Caps_Lock (0x42)
control Control_L (0x25), Control_R (0x69)
mod1 Alt_L (0x40), Meta_L (0xcd)
mod2 Num_Lock (0x4d)
mod3
mod4 Super_L (0x85), Super_R (0x86), Super_L (0xce), Hyper_L (0xcf)
mod5 ISO_Level3_Shift (0x5c), Mode_switch (0xcb)
xmodmap
xmodmap
edited Aug 10 '16 at 21:08
depquid
2,71011230
2,71011230
asked Dec 13 '15 at 18:13
hugomg
1,57031531
1,57031531
No idea exactly what's going on, but if you haven't done so already, you might want to runxev
and press the various key combinations to see if the hardware and up to the Xwindows level is getting distinguishable keypresses to start with.
â Joe
Dec 18 '15 at 23:46
I'm experiencing the very same issue. I wanted to modify comma and dot to also support printing czech and english double quotes (âÂÂ/âÂÂ/âÂÂ) that I have to write using compose key otherwise. I'm usingus(cz_sk_de)
keyboard layout and xmodmap.
â Pavel à  imerda
Aug 6 '16 at 9:13
So what now? It's not practical to waste another bounty nor to start a new question when this one pretty well describes the issue. It looks like a bug in xorg but I haven't found any references. The existing answer is clearly wrong despite being automaticaly awarded.
â Pavel à  imerda
Sep 5 '16 at 16:26
I ended giving up and use different keybinds that I know work :/ I agree that this does look like a bug but I don' t know what system its related to and where to report it...
â hugomg
Sep 5 '16 at 17:20
I found some information here... blog.azundris.com/archives/193-X-treme-pain-XKB-vs-XModMap.html
â Pavel à  imerda
Oct 1 '16 at 20:20
add a comment |Â
No idea exactly what's going on, but if you haven't done so already, you might want to runxev
and press the various key combinations to see if the hardware and up to the Xwindows level is getting distinguishable keypresses to start with.
â Joe
Dec 18 '15 at 23:46
I'm experiencing the very same issue. I wanted to modify comma and dot to also support printing czech and english double quotes (âÂÂ/âÂÂ/âÂÂ) that I have to write using compose key otherwise. I'm usingus(cz_sk_de)
keyboard layout and xmodmap.
â Pavel à  imerda
Aug 6 '16 at 9:13
So what now? It's not practical to waste another bounty nor to start a new question when this one pretty well describes the issue. It looks like a bug in xorg but I haven't found any references. The existing answer is clearly wrong despite being automaticaly awarded.
â Pavel à  imerda
Sep 5 '16 at 16:26
I ended giving up and use different keybinds that I know work :/ I agree that this does look like a bug but I don' t know what system its related to and where to report it...
â hugomg
Sep 5 '16 at 17:20
I found some information here... blog.azundris.com/archives/193-X-treme-pain-XKB-vs-XModMap.html
â Pavel à  imerda
Oct 1 '16 at 20:20
No idea exactly what's going on, but if you haven't done so already, you might want to run
xev
and press the various key combinations to see if the hardware and up to the Xwindows level is getting distinguishable keypresses to start with.â Joe
Dec 18 '15 at 23:46
No idea exactly what's going on, but if you haven't done so already, you might want to run
xev
and press the various key combinations to see if the hardware and up to the Xwindows level is getting distinguishable keypresses to start with.â Joe
Dec 18 '15 at 23:46
I'm experiencing the very same issue. I wanted to modify comma and dot to also support printing czech and english double quotes (âÂÂ/âÂÂ/âÂÂ) that I have to write using compose key otherwise. I'm using
us(cz_sk_de)
keyboard layout and xmodmap.â Pavel à  imerda
Aug 6 '16 at 9:13
I'm experiencing the very same issue. I wanted to modify comma and dot to also support printing czech and english double quotes (âÂÂ/âÂÂ/âÂÂ) that I have to write using compose key otherwise. I'm using
us(cz_sk_de)
keyboard layout and xmodmap.â Pavel à  imerda
Aug 6 '16 at 9:13
So what now? It's not practical to waste another bounty nor to start a new question when this one pretty well describes the issue. It looks like a bug in xorg but I haven't found any references. The existing answer is clearly wrong despite being automaticaly awarded.
â Pavel à  imerda
Sep 5 '16 at 16:26
So what now? It's not practical to waste another bounty nor to start a new question when this one pretty well describes the issue. It looks like a bug in xorg but I haven't found any references. The existing answer is clearly wrong despite being automaticaly awarded.
â Pavel à  imerda
Sep 5 '16 at 16:26
I ended giving up and use different keybinds that I know work :/ I agree that this does look like a bug but I don' t know what system its related to and where to report it...
â hugomg
Sep 5 '16 at 17:20
I ended giving up and use different keybinds that I know work :/ I agree that this does look like a bug but I don' t know what system its related to and where to report it...
â hugomg
Sep 5 '16 at 17:20
I found some information here... blog.azundris.com/archives/193-X-treme-pain-XKB-vs-XModMap.html
â Pavel à  imerda
Oct 1 '16 at 20:20
I found some information here... blog.azundris.com/archives/193-X-treme-pain-XKB-vs-XModMap.html
â Pavel à  imerda
Oct 1 '16 at 20:20
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
4
down vote
accepted
Using xmodmap to configure individual key mappings
It is time to write down results of my own research.
I thought that I must have missed something in xmodmap and that it is just not very well documented and people are confused. But it turned out that X.Org design regarding XKB and xmodmap is just stupid.
Epic fail: xmodmap
You can use xmodmap to redefine existing mappings as long as those mappings actually exist in your original keyboard layout. In the case described in the question you cannot extend behavior of any keys to use AltGr. You can only change the AltGr keysyms for keycodes that are already using AltGr.
See also: http://blog.azundris.com/archives/193-X-treme-pain-XKB-vs-XModMap.html
Workaround: Mode_switch
This workaround is described in the answer by @Ned64. You can remap AltGr
from ISO_Level3_Shift
to Mode_switch
.
I successfully used the following command line to remap AltGr
.
xmodmap -e 'keycode 108 = Mode_switch'
The disadvantage is that it will break your current keyboard layout but you can recreate all the mappings one by one using xmodmap
as @Ned64 already mentioned.
Workaround: Modified keyboard layout
I'm using us(cz_sk_de)
as my keyboard layout and I tried to modify it by adding configuration for keys I wanted to extend.
key <AB08> [ comma, less, doublelowquotemark, leftdoublequotemark ] ;
key <AB09> [ period, greater, ellipsis, rightdoublequotemark ] ;
(In section xkb_symbols "cz_sk_de"
of /usr/share/X11/xkb/symbols/us
)
Just reset the keyboard layout to use the modified version.
setxkbmap 'us(cz_sk_de)'
Now you can (1) type Czech and English quotation marks and ellipses using combinations of ,
, .
, Shift
and AltGr
keys and/or (2) remap those keys using xmodmap
now that they are defined.
The main disadvantage is that setxkbmap
doesn't seem to support arbitrary locations for keyboard layouts and therefore you need to write to system configuration instead of your home directory.
Conclusion
This seems to be an example of overengineered and bad design of X.Org where even such a trivial thing as mapping a key code and a combination of modifiers into a symbol turns out to be a problem. The tools don't seem to provide a reasonable way to just change individual key mappings in user configuration without any side effects.
" you cannot extend behavior of any keys to use AltGr" -- looks like this was the problem all along! Thanks.
â hugomg
Oct 1 '16 at 22:30
add a comment |Â
up vote
4
down vote
Step one: Make AltGr usable
I found out that AltGr-modified Keys only work on my system if I also remap the AltGr-Key to Mode_switch
, like this:
xmodmap -e "keycode 108 = Mode_switch Mode_switch Mode_switch Mode_switch"
If you have a different keyboard you may need to replace the 108
with your code, check by typing
xmodmap -pke | grep Alt_R
then use that number. (The key is normally called Alt_R
on systems I know.)
Alternatively, this may also work if Alt_R is not yet assigned to something else:
xmodmap -e "keysym Alt_R = Mode_switch Mode_switch Mode_switch Mode_switch"
Your AltGr modifier will now serve position 3 (with Shift: 4) within your modifier list.
Step two: Assign keys as required
You can assign AltGr-variants for any key of you keyboard you wish. If you have other keys which do not correspond to the desired code now, you need to re-assign these just like your other keys (the ones you tested).
Step three: Convert this into a script
Now just take your xmodmap
commands and write all (but only) modifications to your default keyboard into a file - that is faster than loading a complete keymap. Start this script once after each login and whenever the keymap gets reset by some process.
I have experimented with this a lot over the years, under Solaris, IRIX and Linux, and to my knowledge this is the only solution to get AltGr working - and it has worked well for me for more than 20 years.
1
With this, the right window key started acting as "3" instead of "1". However, now all the existing altgr modifiers stopped working (I guess it would have needed to be a "5" instead of a "3" for them to work?)
â hugomg
Aug 10 '16 at 17:28
Thanks for trying this. Please postxmodmap -pm
andxmodmap -pke | grep -w SOMECHANGEDKEY
in this situation, for a key which does not work anymore.
â Ned64
Aug 10 '16 at 17:32
(then we will need to add the new modifier usingxmodmap
according to your output)
â Ned64
Aug 10 '16 at 17:37
xmodmap -pke | grep Alt_R
doesn't return any results on my system. My system is Lenovo ThinkPad X230 with Gentoo stable. I also tried withgrep -i
to no avail.
â Pavel à  imerda
Aug 12 '16 at 7:23
I tried it and the problem is that accented letters fromus(cz_sk_de)
stopped working for me. Therefore this answer doesn't work for me and will not work for many others.
â Pavel à  imerda
Aug 12 '16 at 7:54
 |Â
show 7 more comments
up vote
1
down vote
Apparently, xmodmap does not read the default AltGR as it should, it may be limited to specific keyboard layouts, maybe it's all non-US layouts, either way, the real problem is t hat while you can replace your keyboard layout, some people might not really want to do that as they need to use special characters on the layout they are used to (like scandinavian keyboard layouts which have characters like ðþæöáúÃÂÃ³Ã¥à ¯ and so on) that would be a pain to configure for other keyboard layouts.
You can run
xmodmap -e "keycode 108 = Mode_switch"
To rebind AltGR to something xmodmap can work with, and indeed, the 3rd assignment of a keycoad will be output when you press AltGR now, however it will completely break the original keyboard layout as no AltGR keybindings will work anymore with the AltGR key.
I have found two workarounds that do not break my existing keyboard layout and does not involve switching layouts, one is to bind Mode_switch to another key.
The ideal key for this is Super_R which is right next to AltGR, the keycode for it is 134. However not all keyboards have them and in my case on a laptop I do not have it either, so I decided to bind it to the last remaining key that I practically never use, Right Control.
xmodmap -e "keycode 105 = Mode_switch"
I have an american physical keyboard layout, but european layout configuration, and the less/greater/bar key (also known as ISO_Backslash, although that is not recognized by xmodmap itself) usually next to Z on such keyboards is missing. I bound that to Menu (135) but it could serve as an alternative to R_Ctrl and Super_R
This is a dirty fix I suppose.
The second workaround took a bit longer to figure out. Using sxhkd (xbindkeys alternative)
If you add this to ~/.config/sxhkd/sxhkdrc:
~ISO_Level3_Shift
xdotool key Mode_switch
Your AltGR will function as normal, but when it is pressed, Mode_switch gets toggled (kinda like caps lock, but for Mode_switch) and any xmodmap keys that use it will be locked into AltGR mode until you press AltGR again to untoggle it. It should be a simple matter to make a script to untoggle it automatically when the key is released but my attempts to do so were quite buggy, to say the least.
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
Using xmodmap to configure individual key mappings
It is time to write down results of my own research.
I thought that I must have missed something in xmodmap and that it is just not very well documented and people are confused. But it turned out that X.Org design regarding XKB and xmodmap is just stupid.
Epic fail: xmodmap
You can use xmodmap to redefine existing mappings as long as those mappings actually exist in your original keyboard layout. In the case described in the question you cannot extend behavior of any keys to use AltGr. You can only change the AltGr keysyms for keycodes that are already using AltGr.
See also: http://blog.azundris.com/archives/193-X-treme-pain-XKB-vs-XModMap.html
Workaround: Mode_switch
This workaround is described in the answer by @Ned64. You can remap AltGr
from ISO_Level3_Shift
to Mode_switch
.
I successfully used the following command line to remap AltGr
.
xmodmap -e 'keycode 108 = Mode_switch'
The disadvantage is that it will break your current keyboard layout but you can recreate all the mappings one by one using xmodmap
as @Ned64 already mentioned.
Workaround: Modified keyboard layout
I'm using us(cz_sk_de)
as my keyboard layout and I tried to modify it by adding configuration for keys I wanted to extend.
key <AB08> [ comma, less, doublelowquotemark, leftdoublequotemark ] ;
key <AB09> [ period, greater, ellipsis, rightdoublequotemark ] ;
(In section xkb_symbols "cz_sk_de"
of /usr/share/X11/xkb/symbols/us
)
Just reset the keyboard layout to use the modified version.
setxkbmap 'us(cz_sk_de)'
Now you can (1) type Czech and English quotation marks and ellipses using combinations of ,
, .
, Shift
and AltGr
keys and/or (2) remap those keys using xmodmap
now that they are defined.
The main disadvantage is that setxkbmap
doesn't seem to support arbitrary locations for keyboard layouts and therefore you need to write to system configuration instead of your home directory.
Conclusion
This seems to be an example of overengineered and bad design of X.Org where even such a trivial thing as mapping a key code and a combination of modifiers into a symbol turns out to be a problem. The tools don't seem to provide a reasonable way to just change individual key mappings in user configuration without any side effects.
" you cannot extend behavior of any keys to use AltGr" -- looks like this was the problem all along! Thanks.
â hugomg
Oct 1 '16 at 22:30
add a comment |Â
up vote
4
down vote
accepted
Using xmodmap to configure individual key mappings
It is time to write down results of my own research.
I thought that I must have missed something in xmodmap and that it is just not very well documented and people are confused. But it turned out that X.Org design regarding XKB and xmodmap is just stupid.
Epic fail: xmodmap
You can use xmodmap to redefine existing mappings as long as those mappings actually exist in your original keyboard layout. In the case described in the question you cannot extend behavior of any keys to use AltGr. You can only change the AltGr keysyms for keycodes that are already using AltGr.
See also: http://blog.azundris.com/archives/193-X-treme-pain-XKB-vs-XModMap.html
Workaround: Mode_switch
This workaround is described in the answer by @Ned64. You can remap AltGr
from ISO_Level3_Shift
to Mode_switch
.
I successfully used the following command line to remap AltGr
.
xmodmap -e 'keycode 108 = Mode_switch'
The disadvantage is that it will break your current keyboard layout but you can recreate all the mappings one by one using xmodmap
as @Ned64 already mentioned.
Workaround: Modified keyboard layout
I'm using us(cz_sk_de)
as my keyboard layout and I tried to modify it by adding configuration for keys I wanted to extend.
key <AB08> [ comma, less, doublelowquotemark, leftdoublequotemark ] ;
key <AB09> [ period, greater, ellipsis, rightdoublequotemark ] ;
(In section xkb_symbols "cz_sk_de"
of /usr/share/X11/xkb/symbols/us
)
Just reset the keyboard layout to use the modified version.
setxkbmap 'us(cz_sk_de)'
Now you can (1) type Czech and English quotation marks and ellipses using combinations of ,
, .
, Shift
and AltGr
keys and/or (2) remap those keys using xmodmap
now that they are defined.
The main disadvantage is that setxkbmap
doesn't seem to support arbitrary locations for keyboard layouts and therefore you need to write to system configuration instead of your home directory.
Conclusion
This seems to be an example of overengineered and bad design of X.Org where even such a trivial thing as mapping a key code and a combination of modifiers into a symbol turns out to be a problem. The tools don't seem to provide a reasonable way to just change individual key mappings in user configuration without any side effects.
" you cannot extend behavior of any keys to use AltGr" -- looks like this was the problem all along! Thanks.
â hugomg
Oct 1 '16 at 22:30
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
Using xmodmap to configure individual key mappings
It is time to write down results of my own research.
I thought that I must have missed something in xmodmap and that it is just not very well documented and people are confused. But it turned out that X.Org design regarding XKB and xmodmap is just stupid.
Epic fail: xmodmap
You can use xmodmap to redefine existing mappings as long as those mappings actually exist in your original keyboard layout. In the case described in the question you cannot extend behavior of any keys to use AltGr. You can only change the AltGr keysyms for keycodes that are already using AltGr.
See also: http://blog.azundris.com/archives/193-X-treme-pain-XKB-vs-XModMap.html
Workaround: Mode_switch
This workaround is described in the answer by @Ned64. You can remap AltGr
from ISO_Level3_Shift
to Mode_switch
.
I successfully used the following command line to remap AltGr
.
xmodmap -e 'keycode 108 = Mode_switch'
The disadvantage is that it will break your current keyboard layout but you can recreate all the mappings one by one using xmodmap
as @Ned64 already mentioned.
Workaround: Modified keyboard layout
I'm using us(cz_sk_de)
as my keyboard layout and I tried to modify it by adding configuration for keys I wanted to extend.
key <AB08> [ comma, less, doublelowquotemark, leftdoublequotemark ] ;
key <AB09> [ period, greater, ellipsis, rightdoublequotemark ] ;
(In section xkb_symbols "cz_sk_de"
of /usr/share/X11/xkb/symbols/us
)
Just reset the keyboard layout to use the modified version.
setxkbmap 'us(cz_sk_de)'
Now you can (1) type Czech and English quotation marks and ellipses using combinations of ,
, .
, Shift
and AltGr
keys and/or (2) remap those keys using xmodmap
now that they are defined.
The main disadvantage is that setxkbmap
doesn't seem to support arbitrary locations for keyboard layouts and therefore you need to write to system configuration instead of your home directory.
Conclusion
This seems to be an example of overengineered and bad design of X.Org where even such a trivial thing as mapping a key code and a combination of modifiers into a symbol turns out to be a problem. The tools don't seem to provide a reasonable way to just change individual key mappings in user configuration without any side effects.
Using xmodmap to configure individual key mappings
It is time to write down results of my own research.
I thought that I must have missed something in xmodmap and that it is just not very well documented and people are confused. But it turned out that X.Org design regarding XKB and xmodmap is just stupid.
Epic fail: xmodmap
You can use xmodmap to redefine existing mappings as long as those mappings actually exist in your original keyboard layout. In the case described in the question you cannot extend behavior of any keys to use AltGr. You can only change the AltGr keysyms for keycodes that are already using AltGr.
See also: http://blog.azundris.com/archives/193-X-treme-pain-XKB-vs-XModMap.html
Workaround: Mode_switch
This workaround is described in the answer by @Ned64. You can remap AltGr
from ISO_Level3_Shift
to Mode_switch
.
I successfully used the following command line to remap AltGr
.
xmodmap -e 'keycode 108 = Mode_switch'
The disadvantage is that it will break your current keyboard layout but you can recreate all the mappings one by one using xmodmap
as @Ned64 already mentioned.
Workaround: Modified keyboard layout
I'm using us(cz_sk_de)
as my keyboard layout and I tried to modify it by adding configuration for keys I wanted to extend.
key <AB08> [ comma, less, doublelowquotemark, leftdoublequotemark ] ;
key <AB09> [ period, greater, ellipsis, rightdoublequotemark ] ;
(In section xkb_symbols "cz_sk_de"
of /usr/share/X11/xkb/symbols/us
)
Just reset the keyboard layout to use the modified version.
setxkbmap 'us(cz_sk_de)'
Now you can (1) type Czech and English quotation marks and ellipses using combinations of ,
, .
, Shift
and AltGr
keys and/or (2) remap those keys using xmodmap
now that they are defined.
The main disadvantage is that setxkbmap
doesn't seem to support arbitrary locations for keyboard layouts and therefore you need to write to system configuration instead of your home directory.
Conclusion
This seems to be an example of overengineered and bad design of X.Org where even such a trivial thing as mapping a key code and a combination of modifiers into a symbol turns out to be a problem. The tools don't seem to provide a reasonable way to just change individual key mappings in user configuration without any side effects.
answered Oct 1 '16 at 21:02
Pavel à  imerda
3,48911529
3,48911529
" you cannot extend behavior of any keys to use AltGr" -- looks like this was the problem all along! Thanks.
â hugomg
Oct 1 '16 at 22:30
add a comment |Â
" you cannot extend behavior of any keys to use AltGr" -- looks like this was the problem all along! Thanks.
â hugomg
Oct 1 '16 at 22:30
" you cannot extend behavior of any keys to use AltGr" -- looks like this was the problem all along! Thanks.
â hugomg
Oct 1 '16 at 22:30
" you cannot extend behavior of any keys to use AltGr" -- looks like this was the problem all along! Thanks.
â hugomg
Oct 1 '16 at 22:30
add a comment |Â
up vote
4
down vote
Step one: Make AltGr usable
I found out that AltGr-modified Keys only work on my system if I also remap the AltGr-Key to Mode_switch
, like this:
xmodmap -e "keycode 108 = Mode_switch Mode_switch Mode_switch Mode_switch"
If you have a different keyboard you may need to replace the 108
with your code, check by typing
xmodmap -pke | grep Alt_R
then use that number. (The key is normally called Alt_R
on systems I know.)
Alternatively, this may also work if Alt_R is not yet assigned to something else:
xmodmap -e "keysym Alt_R = Mode_switch Mode_switch Mode_switch Mode_switch"
Your AltGr modifier will now serve position 3 (with Shift: 4) within your modifier list.
Step two: Assign keys as required
You can assign AltGr-variants for any key of you keyboard you wish. If you have other keys which do not correspond to the desired code now, you need to re-assign these just like your other keys (the ones you tested).
Step three: Convert this into a script
Now just take your xmodmap
commands and write all (but only) modifications to your default keyboard into a file - that is faster than loading a complete keymap. Start this script once after each login and whenever the keymap gets reset by some process.
I have experimented with this a lot over the years, under Solaris, IRIX and Linux, and to my knowledge this is the only solution to get AltGr working - and it has worked well for me for more than 20 years.
1
With this, the right window key started acting as "3" instead of "1". However, now all the existing altgr modifiers stopped working (I guess it would have needed to be a "5" instead of a "3" for them to work?)
â hugomg
Aug 10 '16 at 17:28
Thanks for trying this. Please postxmodmap -pm
andxmodmap -pke | grep -w SOMECHANGEDKEY
in this situation, for a key which does not work anymore.
â Ned64
Aug 10 '16 at 17:32
(then we will need to add the new modifier usingxmodmap
according to your output)
â Ned64
Aug 10 '16 at 17:37
xmodmap -pke | grep Alt_R
doesn't return any results on my system. My system is Lenovo ThinkPad X230 with Gentoo stable. I also tried withgrep -i
to no avail.
â Pavel à  imerda
Aug 12 '16 at 7:23
I tried it and the problem is that accented letters fromus(cz_sk_de)
stopped working for me. Therefore this answer doesn't work for me and will not work for many others.
â Pavel à  imerda
Aug 12 '16 at 7:54
 |Â
show 7 more comments
up vote
4
down vote
Step one: Make AltGr usable
I found out that AltGr-modified Keys only work on my system if I also remap the AltGr-Key to Mode_switch
, like this:
xmodmap -e "keycode 108 = Mode_switch Mode_switch Mode_switch Mode_switch"
If you have a different keyboard you may need to replace the 108
with your code, check by typing
xmodmap -pke | grep Alt_R
then use that number. (The key is normally called Alt_R
on systems I know.)
Alternatively, this may also work if Alt_R is not yet assigned to something else:
xmodmap -e "keysym Alt_R = Mode_switch Mode_switch Mode_switch Mode_switch"
Your AltGr modifier will now serve position 3 (with Shift: 4) within your modifier list.
Step two: Assign keys as required
You can assign AltGr-variants for any key of you keyboard you wish. If you have other keys which do not correspond to the desired code now, you need to re-assign these just like your other keys (the ones you tested).
Step three: Convert this into a script
Now just take your xmodmap
commands and write all (but only) modifications to your default keyboard into a file - that is faster than loading a complete keymap. Start this script once after each login and whenever the keymap gets reset by some process.
I have experimented with this a lot over the years, under Solaris, IRIX and Linux, and to my knowledge this is the only solution to get AltGr working - and it has worked well for me for more than 20 years.
1
With this, the right window key started acting as "3" instead of "1". However, now all the existing altgr modifiers stopped working (I guess it would have needed to be a "5" instead of a "3" for them to work?)
â hugomg
Aug 10 '16 at 17:28
Thanks for trying this. Please postxmodmap -pm
andxmodmap -pke | grep -w SOMECHANGEDKEY
in this situation, for a key which does not work anymore.
â Ned64
Aug 10 '16 at 17:32
(then we will need to add the new modifier usingxmodmap
according to your output)
â Ned64
Aug 10 '16 at 17:37
xmodmap -pke | grep Alt_R
doesn't return any results on my system. My system is Lenovo ThinkPad X230 with Gentoo stable. I also tried withgrep -i
to no avail.
â Pavel à  imerda
Aug 12 '16 at 7:23
I tried it and the problem is that accented letters fromus(cz_sk_de)
stopped working for me. Therefore this answer doesn't work for me and will not work for many others.
â Pavel à  imerda
Aug 12 '16 at 7:54
 |Â
show 7 more comments
up vote
4
down vote
up vote
4
down vote
Step one: Make AltGr usable
I found out that AltGr-modified Keys only work on my system if I also remap the AltGr-Key to Mode_switch
, like this:
xmodmap -e "keycode 108 = Mode_switch Mode_switch Mode_switch Mode_switch"
If you have a different keyboard you may need to replace the 108
with your code, check by typing
xmodmap -pke | grep Alt_R
then use that number. (The key is normally called Alt_R
on systems I know.)
Alternatively, this may also work if Alt_R is not yet assigned to something else:
xmodmap -e "keysym Alt_R = Mode_switch Mode_switch Mode_switch Mode_switch"
Your AltGr modifier will now serve position 3 (with Shift: 4) within your modifier list.
Step two: Assign keys as required
You can assign AltGr-variants for any key of you keyboard you wish. If you have other keys which do not correspond to the desired code now, you need to re-assign these just like your other keys (the ones you tested).
Step three: Convert this into a script
Now just take your xmodmap
commands and write all (but only) modifications to your default keyboard into a file - that is faster than loading a complete keymap. Start this script once after each login and whenever the keymap gets reset by some process.
I have experimented with this a lot over the years, under Solaris, IRIX and Linux, and to my knowledge this is the only solution to get AltGr working - and it has worked well for me for more than 20 years.
Step one: Make AltGr usable
I found out that AltGr-modified Keys only work on my system if I also remap the AltGr-Key to Mode_switch
, like this:
xmodmap -e "keycode 108 = Mode_switch Mode_switch Mode_switch Mode_switch"
If you have a different keyboard you may need to replace the 108
with your code, check by typing
xmodmap -pke | grep Alt_R
then use that number. (The key is normally called Alt_R
on systems I know.)
Alternatively, this may also work if Alt_R is not yet assigned to something else:
xmodmap -e "keysym Alt_R = Mode_switch Mode_switch Mode_switch Mode_switch"
Your AltGr modifier will now serve position 3 (with Shift: 4) within your modifier list.
Step two: Assign keys as required
You can assign AltGr-variants for any key of you keyboard you wish. If you have other keys which do not correspond to the desired code now, you need to re-assign these just like your other keys (the ones you tested).
Step three: Convert this into a script
Now just take your xmodmap
commands and write all (but only) modifications to your default keyboard into a file - that is faster than loading a complete keymap. Start this script once after each login and whenever the keymap gets reset by some process.
I have experimented with this a lot over the years, under Solaris, IRIX and Linux, and to my knowledge this is the only solution to get AltGr working - and it has worked well for me for more than 20 years.
edited Sep 7 '16 at 16:54
Michael Mrozekâ¦
59k27186207
59k27186207
answered Aug 10 '16 at 15:13
Ned64
2,48411135
2,48411135
1
With this, the right window key started acting as "3" instead of "1". However, now all the existing altgr modifiers stopped working (I guess it would have needed to be a "5" instead of a "3" for them to work?)
â hugomg
Aug 10 '16 at 17:28
Thanks for trying this. Please postxmodmap -pm
andxmodmap -pke | grep -w SOMECHANGEDKEY
in this situation, for a key which does not work anymore.
â Ned64
Aug 10 '16 at 17:32
(then we will need to add the new modifier usingxmodmap
according to your output)
â Ned64
Aug 10 '16 at 17:37
xmodmap -pke | grep Alt_R
doesn't return any results on my system. My system is Lenovo ThinkPad X230 with Gentoo stable. I also tried withgrep -i
to no avail.
â Pavel à  imerda
Aug 12 '16 at 7:23
I tried it and the problem is that accented letters fromus(cz_sk_de)
stopped working for me. Therefore this answer doesn't work for me and will not work for many others.
â Pavel à  imerda
Aug 12 '16 at 7:54
 |Â
show 7 more comments
1
With this, the right window key started acting as "3" instead of "1". However, now all the existing altgr modifiers stopped working (I guess it would have needed to be a "5" instead of a "3" for them to work?)
â hugomg
Aug 10 '16 at 17:28
Thanks for trying this. Please postxmodmap -pm
andxmodmap -pke | grep -w SOMECHANGEDKEY
in this situation, for a key which does not work anymore.
â Ned64
Aug 10 '16 at 17:32
(then we will need to add the new modifier usingxmodmap
according to your output)
â Ned64
Aug 10 '16 at 17:37
xmodmap -pke | grep Alt_R
doesn't return any results on my system. My system is Lenovo ThinkPad X230 with Gentoo stable. I also tried withgrep -i
to no avail.
â Pavel à  imerda
Aug 12 '16 at 7:23
I tried it and the problem is that accented letters fromus(cz_sk_de)
stopped working for me. Therefore this answer doesn't work for me and will not work for many others.
â Pavel à  imerda
Aug 12 '16 at 7:54
1
1
With this, the right window key started acting as "3" instead of "1". However, now all the existing altgr modifiers stopped working (I guess it would have needed to be a "5" instead of a "3" for them to work?)
â hugomg
Aug 10 '16 at 17:28
With this, the right window key started acting as "3" instead of "1". However, now all the existing altgr modifiers stopped working (I guess it would have needed to be a "5" instead of a "3" for them to work?)
â hugomg
Aug 10 '16 at 17:28
Thanks for trying this. Please post
xmodmap -pm
and xmodmap -pke | grep -w SOMECHANGEDKEY
in this situation, for a key which does not work anymore.â Ned64
Aug 10 '16 at 17:32
Thanks for trying this. Please post
xmodmap -pm
and xmodmap -pke | grep -w SOMECHANGEDKEY
in this situation, for a key which does not work anymore.â Ned64
Aug 10 '16 at 17:32
(then we will need to add the new modifier using
xmodmap
according to your output)â Ned64
Aug 10 '16 at 17:37
(then we will need to add the new modifier using
xmodmap
according to your output)â Ned64
Aug 10 '16 at 17:37
xmodmap -pke | grep Alt_R
doesn't return any results on my system. My system is Lenovo ThinkPad X230 with Gentoo stable. I also tried with grep -i
to no avail.â Pavel à  imerda
Aug 12 '16 at 7:23
xmodmap -pke | grep Alt_R
doesn't return any results on my system. My system is Lenovo ThinkPad X230 with Gentoo stable. I also tried with grep -i
to no avail.â Pavel à  imerda
Aug 12 '16 at 7:23
I tried it and the problem is that accented letters from
us(cz_sk_de)
stopped working for me. Therefore this answer doesn't work for me and will not work for many others.â Pavel à  imerda
Aug 12 '16 at 7:54
I tried it and the problem is that accented letters from
us(cz_sk_de)
stopped working for me. Therefore this answer doesn't work for me and will not work for many others.â Pavel à  imerda
Aug 12 '16 at 7:54
 |Â
show 7 more comments
up vote
1
down vote
Apparently, xmodmap does not read the default AltGR as it should, it may be limited to specific keyboard layouts, maybe it's all non-US layouts, either way, the real problem is t hat while you can replace your keyboard layout, some people might not really want to do that as they need to use special characters on the layout they are used to (like scandinavian keyboard layouts which have characters like ðþæöáúÃÂÃ³Ã¥à ¯ and so on) that would be a pain to configure for other keyboard layouts.
You can run
xmodmap -e "keycode 108 = Mode_switch"
To rebind AltGR to something xmodmap can work with, and indeed, the 3rd assignment of a keycoad will be output when you press AltGR now, however it will completely break the original keyboard layout as no AltGR keybindings will work anymore with the AltGR key.
I have found two workarounds that do not break my existing keyboard layout and does not involve switching layouts, one is to bind Mode_switch to another key.
The ideal key for this is Super_R which is right next to AltGR, the keycode for it is 134. However not all keyboards have them and in my case on a laptop I do not have it either, so I decided to bind it to the last remaining key that I practically never use, Right Control.
xmodmap -e "keycode 105 = Mode_switch"
I have an american physical keyboard layout, but european layout configuration, and the less/greater/bar key (also known as ISO_Backslash, although that is not recognized by xmodmap itself) usually next to Z on such keyboards is missing. I bound that to Menu (135) but it could serve as an alternative to R_Ctrl and Super_R
This is a dirty fix I suppose.
The second workaround took a bit longer to figure out. Using sxhkd (xbindkeys alternative)
If you add this to ~/.config/sxhkd/sxhkdrc:
~ISO_Level3_Shift
xdotool key Mode_switch
Your AltGR will function as normal, but when it is pressed, Mode_switch gets toggled (kinda like caps lock, but for Mode_switch) and any xmodmap keys that use it will be locked into AltGR mode until you press AltGR again to untoggle it. It should be a simple matter to make a script to untoggle it automatically when the key is released but my attempts to do so were quite buggy, to say the least.
add a comment |Â
up vote
1
down vote
Apparently, xmodmap does not read the default AltGR as it should, it may be limited to specific keyboard layouts, maybe it's all non-US layouts, either way, the real problem is t hat while you can replace your keyboard layout, some people might not really want to do that as they need to use special characters on the layout they are used to (like scandinavian keyboard layouts which have characters like ðþæöáúÃÂÃ³Ã¥à ¯ and so on) that would be a pain to configure for other keyboard layouts.
You can run
xmodmap -e "keycode 108 = Mode_switch"
To rebind AltGR to something xmodmap can work with, and indeed, the 3rd assignment of a keycoad will be output when you press AltGR now, however it will completely break the original keyboard layout as no AltGR keybindings will work anymore with the AltGR key.
I have found two workarounds that do not break my existing keyboard layout and does not involve switching layouts, one is to bind Mode_switch to another key.
The ideal key for this is Super_R which is right next to AltGR, the keycode for it is 134. However not all keyboards have them and in my case on a laptop I do not have it either, so I decided to bind it to the last remaining key that I practically never use, Right Control.
xmodmap -e "keycode 105 = Mode_switch"
I have an american physical keyboard layout, but european layout configuration, and the less/greater/bar key (also known as ISO_Backslash, although that is not recognized by xmodmap itself) usually next to Z on such keyboards is missing. I bound that to Menu (135) but it could serve as an alternative to R_Ctrl and Super_R
This is a dirty fix I suppose.
The second workaround took a bit longer to figure out. Using sxhkd (xbindkeys alternative)
If you add this to ~/.config/sxhkd/sxhkdrc:
~ISO_Level3_Shift
xdotool key Mode_switch
Your AltGR will function as normal, but when it is pressed, Mode_switch gets toggled (kinda like caps lock, but for Mode_switch) and any xmodmap keys that use it will be locked into AltGR mode until you press AltGR again to untoggle it. It should be a simple matter to make a script to untoggle it automatically when the key is released but my attempts to do so were quite buggy, to say the least.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Apparently, xmodmap does not read the default AltGR as it should, it may be limited to specific keyboard layouts, maybe it's all non-US layouts, either way, the real problem is t hat while you can replace your keyboard layout, some people might not really want to do that as they need to use special characters on the layout they are used to (like scandinavian keyboard layouts which have characters like ðþæöáúÃÂÃ³Ã¥à ¯ and so on) that would be a pain to configure for other keyboard layouts.
You can run
xmodmap -e "keycode 108 = Mode_switch"
To rebind AltGR to something xmodmap can work with, and indeed, the 3rd assignment of a keycoad will be output when you press AltGR now, however it will completely break the original keyboard layout as no AltGR keybindings will work anymore with the AltGR key.
I have found two workarounds that do not break my existing keyboard layout and does not involve switching layouts, one is to bind Mode_switch to another key.
The ideal key for this is Super_R which is right next to AltGR, the keycode for it is 134. However not all keyboards have them and in my case on a laptop I do not have it either, so I decided to bind it to the last remaining key that I practically never use, Right Control.
xmodmap -e "keycode 105 = Mode_switch"
I have an american physical keyboard layout, but european layout configuration, and the less/greater/bar key (also known as ISO_Backslash, although that is not recognized by xmodmap itself) usually next to Z on such keyboards is missing. I bound that to Menu (135) but it could serve as an alternative to R_Ctrl and Super_R
This is a dirty fix I suppose.
The second workaround took a bit longer to figure out. Using sxhkd (xbindkeys alternative)
If you add this to ~/.config/sxhkd/sxhkdrc:
~ISO_Level3_Shift
xdotool key Mode_switch
Your AltGR will function as normal, but when it is pressed, Mode_switch gets toggled (kinda like caps lock, but for Mode_switch) and any xmodmap keys that use it will be locked into AltGR mode until you press AltGR again to untoggle it. It should be a simple matter to make a script to untoggle it automatically when the key is released but my attempts to do so were quite buggy, to say the least.
Apparently, xmodmap does not read the default AltGR as it should, it may be limited to specific keyboard layouts, maybe it's all non-US layouts, either way, the real problem is t hat while you can replace your keyboard layout, some people might not really want to do that as they need to use special characters on the layout they are used to (like scandinavian keyboard layouts which have characters like ðþæöáúÃÂÃ³Ã¥à ¯ and so on) that would be a pain to configure for other keyboard layouts.
You can run
xmodmap -e "keycode 108 = Mode_switch"
To rebind AltGR to something xmodmap can work with, and indeed, the 3rd assignment of a keycoad will be output when you press AltGR now, however it will completely break the original keyboard layout as no AltGR keybindings will work anymore with the AltGR key.
I have found two workarounds that do not break my existing keyboard layout and does not involve switching layouts, one is to bind Mode_switch to another key.
The ideal key for this is Super_R which is right next to AltGR, the keycode for it is 134. However not all keyboards have them and in my case on a laptop I do not have it either, so I decided to bind it to the last remaining key that I practically never use, Right Control.
xmodmap -e "keycode 105 = Mode_switch"
I have an american physical keyboard layout, but european layout configuration, and the less/greater/bar key (also known as ISO_Backslash, although that is not recognized by xmodmap itself) usually next to Z on such keyboards is missing. I bound that to Menu (135) but it could serve as an alternative to R_Ctrl and Super_R
This is a dirty fix I suppose.
The second workaround took a bit longer to figure out. Using sxhkd (xbindkeys alternative)
If you add this to ~/.config/sxhkd/sxhkdrc:
~ISO_Level3_Shift
xdotool key Mode_switch
Your AltGR will function as normal, but when it is pressed, Mode_switch gets toggled (kinda like caps lock, but for Mode_switch) and any xmodmap keys that use it will be locked into AltGR mode until you press AltGR again to untoggle it. It should be a simple matter to make a script to untoggle it automatically when the key is released but my attempts to do so were quite buggy, to say the least.
edited 2 days ago
answered 2 days ago
Cestarian
75111024
75111024
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f249122%2fwhy-do-my-xmodmap-binds-involving-altgr-only-work-on-some-keys%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
No idea exactly what's going on, but if you haven't done so already, you might want to run
xev
and press the various key combinations to see if the hardware and up to the Xwindows level is getting distinguishable keypresses to start with.â Joe
Dec 18 '15 at 23:46
I'm experiencing the very same issue. I wanted to modify comma and dot to also support printing czech and english double quotes (âÂÂ/âÂÂ/âÂÂ) that I have to write using compose key otherwise. I'm using
us(cz_sk_de)
keyboard layout and xmodmap.â Pavel à  imerda
Aug 6 '16 at 9:13
So what now? It's not practical to waste another bounty nor to start a new question when this one pretty well describes the issue. It looks like a bug in xorg but I haven't found any references. The existing answer is clearly wrong despite being automaticaly awarded.
â Pavel à  imerda
Sep 5 '16 at 16:26
I ended giving up and use different keybinds that I know work :/ I agree that this does look like a bug but I don' t know what system its related to and where to report it...
â hugomg
Sep 5 '16 at 17:20
I found some information here... blog.azundris.com/archives/193-X-treme-pain-XKB-vs-XModMap.html
â Pavel à  imerda
Oct 1 '16 at 20:20