27

Playing with xmodmap I encountered a modifier key I hadn't heard of: Mode_switch. It seems to have something to do with inserting special characters.

I assigned it to a key but it seems to have no effect. What is it for? Is it different from ISO_Level3_Shift (Alt Gr)?

27

Mode_switch is the old-style (pre-XKB) name of the key that is called AltGr on many keyboard layouts. It is similar to Shift, in that when you press a key that corresponds to a character, you get a different character if Shift or AltGr is also pressed. Unlike Shift, Mod_switch is not a modifier in the X11 sense because it normally applies to characters, not to function keys, so applications only need to perform a character lookup to obtain the desired effect.

ISO_Level3_Shift is the XKB version of this key. Generally speaking, XKB is a lot more complicated and can do some extra fancy stuff. XKB's mechanism is more general as it allows keyboard layouts to vary in which keys are influenced by which modifiers, it generalizes sticky (CapsLock-style) and simultaneous-press (Shift-style) modifiers and so on.

  • Great to know that ISO_Level3_Shift can act 'stickily', I was looking for that functionality for a long while: unix.stackexchange.com/questions/39014/… – vemv Nov 7 '12 at 23:06
  • @Gilles So, are AltGr and Mode_switch the same keys? If not, in this link, they sound as if they are the same things. Could you clarify this a bit? – Utku Oct 18 '15 at 18:13
  • @Utku Mode_switch and ISO_Level3_Shift do the same thing in slightly different ways. I don't claim to understand the differences; most of the time they don't matter but I do remember that mixing xmodmap with XKB names occasionally caused modifiers not to work right. – Gilles Oct 18 '15 at 19:23
  • @Gilles I also don't understand the differences but I'm ending up either with us(cz_sk_de) features or with custom xmodmap mappings for some keys (comma for example) depending on whether AltGr is Mode_switch or ISO_Level3_Shift but can't get both features at the same time. – Pavel Šimerda Oct 1 '16 at 19:27
  • 1
    Sticky keys are not CapsLock-style. Sticky keys are called “latch” and lock-keys are called locks. Sticky keys are released after the next non-modifier is pressed while lock keys are in effect until they are pressed again. – Guildenstern Nov 10 '17 at 0:01
10

This answer is not meant to contradict @Gilles' answer, but is meant to describe another aspect of Input handling which I feel is "under-illuminated" in his answer.

You can use both ISO_Level3_Shift(Alt-Gr) and Mode_switch at the same time with different results. It requires some configuration, but you can have them both, and use them to produce 6 different keys per physical keyboard key!

You can e.g. configure Tab to be Mode_switch when held with and , then e.g. the key labeled "H" on the keyboard could produce following characters/keys:

h
H
← (Cursor)
← (Symbol)

with H
with ShiftH
with AltGrH
with AltGrShiftH
with TabH
with TabShiftH

So, to come back around to your question: IL3S and Mode_switch can be configured to mean different things, so you can have cursor keys and ~200 useful characters from the (accented) languages, box-drawing, and technical character set on the 35 keys of the 3 letter rows.

To accomplish the above:

# Initial Setup
xmodmap -e 'keycode 23 = Mode_switch ISO_Left_Tab Tab ISO_Left_Tab Tab ISO_Left_Tab'
xmodmap -e 'keycode any = Tab'
xcape -e "Mode_switch=Tab"

example for H:

xmodmap -pke | grep 'h H'
# Make note of the keycode, note the 8 columns after the `=`,
# then edit and feed back into xmodmap with:
xmodmap -e 'keycode  43 = h H lowrightcorner uprightcorner Left leftarrow h H'
  • Wow! I see what you mean in your 2nd last paragraph now, you just made my day 😉 I no longer need to copy and paste from htmlarrows.com to write things like fn: A → B. – Patrick McLaren Jan 13 '17 at 14:31
  • Why tab can not be other keys than iso_left_tab? For example, keycode 23 = Tab ISO_Left_Tab Next Next Next Next. – godblessfq Aug 11 '18 at 11:51
  • @godblessfq : I'm not quite sure, i understand what you are asking. Please create a new question, reference this answer, and @ me in a comment or the Question Text, then I'll see the question and try to help – Alex Stragies Aug 11 '18 at 17:26
  • I have asked the question here:unix.stackexchange.com/questions/461972/… – godblessfq Aug 12 '18 at 1:40
1

Mode_shift in Xkb is a shift key for groups or layouts. If you have a layout with multiple groups, you can hold down this key to access the next group. If you have several layouts, you can hold down this key to shift between layouts (†1).

So Mode_shift is to groups what Shift (or Shift_L and Shift_R, to use the keysym names) is to levels.

This might become more clear if we consider that Mode_shift has an alias called ISO_Group_Shift (†2). There are also keys called ISO_Group_Latch and ISO_Group_Lock which correspond to ISO_Level2_Latch (latch shift) and Shift_Lock, respectively (†3).

There are also a number of aliases for different scripts:

  • kana_switch
  • Arabic_switch
  • Greek_switch
  • Hebrew_switch
  • Hangul_switch

†1: This is based on my understanding of Xkb’s “groups” and “layouts”. It seems that they are treated the same as far as selecting between them with keys like this.

†2: I am basing this on the file keysymdef.h in this Git repository at revision ab8666661fc6 (“Add XF86XK_AudioPreset”, 2017-05-10). On installations you will probably find this file at /usr/include/X11/keysymdef.h.

†3: There is also a key ISO_Lock, a kind of general-purpose lock key.

The meaning of the AltGr key

Gilles mentioned in his answer the connection with the AltGr key:

Mode_switch is the old-style (pre-XKB) name of the key that is called AltGr on many keyboard layouts.

That lead me to suspect that “AltGr” might stand for “alternate/alternative group”, since Mode_switch is used to shift groups. This turned out to be wrong, however. According to the Wikipedia page on the AltGr key, “AltGr” seems to come from IBM keyboards, and in their manuals it says that it is an abbreviation for “alternate graphics”. This makes sense, since it seems likely that using the keyboard to draw “graphics” (box-drawing characters used in text user interfaces) came well before there was good support for switching quickly between multiple scripts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.