Keyboard Mapping - HinTak/cxterm GitHub Wiki

Keyboard mapping in X11

The simpliest way of disabling the NumLock key, and have it always on, is via the numpad:mac xkb option. There are three ways of doing it:

  • via gsettings command-line:
# Check the original setting:
$ gsettings get org.gnome.desktop.input-sources xkb-options
['lv3:ralt_switch']

# Append 'numpad:mac' to original settings:
$ gsettings set org.gnome.desktop.input-sources xkb-options "['lv3:ralt_switch', 'numpad:mac']"

See /usr/share/X11/xkb/types/numpad and /usr/share/X11/xkb/types/extra.

  • via gnome-tweaks GUI:

gnome-tweaks

  • via dconf-editor:

dconf-editor

Using "Num_Lock" as "Clear" as on the mac keyboard (and GOLD on TPU)

We need the Num_Lock key to work differently. Apple laptop and Apple Aluminium (Apple Aluminium (ANSI), Apple Aluminium (ISO), Apple Aluminium (JIS)) have a "Clear" key which we can emulate.

Edit /usr/share/X11/xkb/symbols/pc, line 23:

    key <NMLK> {	[ Num_Lock 		]	};

To

    key <NMLK> {	[ Clear 		]	};

Editing /usr/share/X11/xkb/types/numpad (where numpad:mac lives) with similar changes as /usr/share/X11/xkb/symbols/macintosh_vndr/apple (where the Apple Laptop/Aluminium definitions are) does not work. Alternative to this is to create a new file under /etc/udev/hwdb.d/ remapping keys.

Putty's Function Keys and Keypad mapping

From Putty's documentation: "Application Keypad mode is a way for the server to change the behaviour of the numeric keypad." See:

4.4.3 Changing the action of the function keys and keypad, 4.4.5 Controlling Application Keypad mode, 4.4.6 Using NetHack keypad mode, 4.6.1 Disabling application keypad and cursor keys,

Putty config

VK_BEGIN on X Windows vs VK_CLEAR on Windows, for num_lock + keypad 5 - JDK-4850137, 2003, JDK-4620715 : No way to see the Context Menu key on the windows keyboards, J2SETM 1.5.0 Beta 1 release notes, VK_WINDOWS, VK_CONTEXT_MENU, VK_CLEAR, VK_BEGIN . Found it in Putty's Windows terminal code.

On Solaris, the numpad /- keys produce F24, F25, F26; but in Java we map them to /- anyway. dtterm acts similar to Java. dtterm also produces a 5 when the numpad 5 key is pressed, but numlock is off (F31).

Gnome-terminal

Bug 600659 - Home / End generate wrong control sequences

Stuff we should care about: apparently there are two orthogonal internal states that influence the sequences generated by keys:

- Application Cursor Keys (\e[?1h) vs Normal Cursor Keys (\e[?1l). This modifies the behavior of seven symbols (most of which are accessible by two
physical keys when numlock is off): Home, End, Left, Right, Up, Down and "Begin" (numpad 5 when numlock is off, whatever it is supposed to mean). When
Application Cursor Keys mode is enabled, the escapes begin with \eO rather than \e[.

- Application Keypad (\e=) vs Normal Keypad (\e>). This modifies the behavior of the four numpad math operators only (although the doc says it should
modify the behavior of space, tab and enter too). When Application Keypad mode is enabled, these keys generate escape sequences, rather than plain ascii
characters.

There's also the external state: the NumLock modifier. Whenever NumLock is enabled, numpad keys ignore both of the internal states mentioned above, and
just emit the corresponding digit or ./*-+ symbol. Standalone Home/End keys still depend on App/Normal Cursor Keys mode. Whenever NumLock is disabled,
the ten numpad keys: up, down, left, right, home, end, pgup, pgdn, insert, delete always produce the same escapes as their standalone key counterparts.

Other tips on Debugging

  • xkbcomp :0.0 writes the keymap into server-0_0.xkb.

  • setxkbmap -print shows the active keymap.

  • setxkbmap -option numpad:mac -print sets the option on the client.

  • setxkbmap -print | xkbcomp - $DISPLAY sync's the client with the server.

  • localectl list-x11-keymap-options lists available options. list-locales, list-keymaps, list-x11-keymap-models, list-x11-keymap-layouts, list-x11-keymap-variants, list-x11-keymap-options are other useful options.

  • Check /etc/default/keyboard (This is Ubuntu specific).

  • Check gsettings get org.gnome.settings-daemon.peripherals.keyboard numlock-state

  • Last resort: gsettings set org.gnome.settings-daemon.peripherals.input-devices hotplug-command "/home/<myname>/key_settings.sh"

  • Check Preference >accessibility > Mouse: "Control the Pointer using keypad" and/or Settings > universal Access > pointing and clicking: "Mouse keys". Turn it off!

  • The LED is completely independent - xset led named "Scroll Lock" and similarly for "Num Lock" and "Caps Lock" to turn them on (or of with -led).

Xmodmap

Xmodmap suppport was removed as early as 2010 Oct in Bug 150542 - Keyboard lost in VNC session after launching keyboard capplet, keyboard: Remove horrible xmodmap fallback code.

In gnome 3.6 onwards, Bug 873656 - .Xmodmap file not loaded by Gnome 3.x, [Bug 688906 - Keybard Layout Options override xmodmap]https://bugzilla.gnome.org/show_bug.cgi?id=688906), Bug 674874 - don't read .xmodmap files by default, [Bug 674221 - g-s-d's hotplug-command called only for mouse]((https://bugzilla.gnome.org/show_bug.cgi?id=674221), the settings are forgotten after every suspend/resume; it become invalid when you switch to next ibus input method. Relevant: keyboard: Run a custom command for new keyboards, common: Add hint on how to set the script path, Bug 674251 - Documentation not clear when g-s-d doesn't apply settings after hotplug-command, Bug 635486 - Allow custom command to run on input device hotplug/removal, Bug 348198 - xkb keymap reset when external keyboard plugged in

Compose

See man 5 Compose for usage of a Compose key, via ~/.XCompose.

Gnome

Gnome terminal uses F11 for toggling full-screen - see Help: Keyboard shortcuts and Gnome may use F10: Design: Keyboard Shortcuts.

Wayland

[3.34] Weird numlock behaviour, g-s/master doesn't maintain a consistent numlock state over applications and g-s overview

Table of keyboard shortcuts

systemd config - /etc/vconsole.conf

/etc/X11/xorg.conf.d/00-keyboard.conf

/usr/share/X11/xkb/rules/base.lst , /usr/share/X11/xkb/

keymaps(5), loadkeys(1), dumpkeys(1), showkey(1), xmodmap(1), xkeyboard-config(7) /usr/lib/kbd/keymaps/

Gentoo keyboard layout switching, Dated Ubuntu instructions on Apple Keyboard

Freedesktop Shared default keyboard shortcuts, Gnome HIG Standard Keyboard Shortcuts, GNOME keyboard shortcuts, GNOME 3 Cheat Sheet, Cheat sheet: GNOME 3

⚠️ **GitHub.com Fallback** ⚠️