Linux: Keyboard Tools for Key Layout, Keymapping, Keybinding ⌨

, , …,

This page is a list of Linux keyboard tools and tutorial.

Basic of Keybinding Using Control Panel

The easiest way to add a new keyboard shortcut or keyboard layout, is the system control panel in a graphical user interface (available in any of the Gnome, KDE, Ubuntu, Xfce, LXDE). Usually there's apps named Window Manager, or Keyboard, or Keyboard Layout.

The Window Manager is for all keys that control windows, such as {next/previous window, close window, max window, hide window, move window, cycle workspace, …}. The Keyboard one lets you set keys to launch apps, or swap modifiers. You can change keys for many default actions there. Also, you can create new keys to run a terminal command.

xfce keyboard setting panel 2013-06-01
xfce keyboard setting panel
xfce window manager keys setup  2013-06-07
xfce window manager keys setup

For more advanced keyboarding, there are 2 steps to set keys in general:

Swapping Keys, Remap Keys

xmodmap

xmodmap is a simple tool that lets you remap/swap keys for apps running under X11.

See: Linux: xmodmap Tutorial ⌨

scancode, keycode, keysym

How find the scancode of a key?

First, switch to Virtual Console. 〔☛ Linux: Why & How to Use the Virtual Console ⌨〕 Then, type showkey --scancodes. Then, type any key, it'll print its scancode in hexadecimal. To exit, just wait for 10 seconds.

Note: you must switch to virtual console for this to work. Normal terminal won't work.

See man showkey and showkey --help

How find the the keycode & keysym of a key?

Type xev, then press a key.

See man xev

How to set system keyboard layout?

See: Linux: Set System Keyboard Layout ⌨

Tool to Bind Key

xbindkeys

if your desktop doesn't provide a way to bind a key to launch a script, then you can use xbindkeys.

xbindkeys home page: http://www.nongnu.org/xbindkeys/xbindkeys.html

xbindkeys can bind almost any key or key combination. Example: Caps Lock, ScrLk, Pause, F2, number pad keys, multimedia keys, and special app launch buttons, and also standard modifier key combinations such as ▤ Menu, 【Ctrl+3】, 【❖ Super+3】, etc.

Install: sudo apt-get install xbindkeys. There's also a GUI wrapper: sudo apt-get install xbindkeys-config

You must first create the config file yourself. Do:

xbindkeys -d > ~/.xbindkeysrc

The xbindkeys -d will print out a default config sample file.

Then, either manually modify the config file, when done, sent it a HUP signal to apply your change, like this killall -HUP xbindkeys.

Or, launch the GUI tool to set keys by xbindkeys-config &.

The hard part is the action part. You need to write a shell command. Basically, call command that do what you want, ⁖ switch to a specific app, or press some other key such as 【Ctrl+w】 for close tab. The hard part is figuring out the syntax of this action command.

Tool for Key Actions

Command Tool to Switch Windows: wmctrl

wmctrl is a command line util to manipulate windows. ⁖ {switch, close, move, resize, set title, list, …}.

To install: sudo apt-get install wmctrl

Example use:

Use xprop util to find the name of a app's window class name. 〔☛ Linux: Commands Related to GUI Apps〕)

here's some popular app's window class name:

Global Set Copy Paste to F3 F4, Using xvkbd

xvkbd is a virtual keyboard for X window system

Here's how to set {F2, F3, F4} keys to do {cut, copy, paste}, globally.

Install xvkbd sudo apt-get install xvkbd, and also install sudo apt-get install xbindkeys, then, add these lines into ~/.xbindkeysrc:

#cut
"xvkbd -no-jump-pointer -xsendevent -text "\Cx" 2>/dev/null"
    m:0x0 + c:68
    F2

#copy
"xvkbd -no-jump-pointer -xsendevent -text "\Cc" 2>/dev/null"
    m:0x0 + c:69
    F3

#paste
"xvkbd -no-jump-pointer -xsendevent -text "\Cv" 2>/dev/null"
    m:0x0 + c:70
    F4

(thanks to XueFuqiao)

Tool to Type Other Keys: xdotool

xdotool. «programatically simulate keyboard input and mouse activity. It does this using X11's XTEST extension and other Xlib functions.»

(note: i tried xdotool under Ubuntu/xfce. Doesn't work in my first 30 min of looking into it.)

Install: sudo apt-get install xdotool

Example. Send 【Ctrl+w】 to close tab. xdotool key --delay 40 Control_L+w

Example. Click on upper left corner, (90, 10) pixels. xdotool mousemove 90 10 click 1

(note: i haven't tried using xdotool)

Tool to Expand Abbreviations: AutoKey

AutoKey. For expanding abbrev to full words/text.

Install: sudo apt-get install autokey-gtk (for Gnome) or sudo apt-get install autokey-qt (for KDE)

(note: i haven't tried using AutoKey)

Other Keyboard Tools

xkb: X Keyboard Extension

xkb (X Keyboard Extension) is a more capable system to set keys in X11, than xmodmap.

setxkbmap → set the keyboard using the X Keyboard Extension.

xkb tutorial https://wiki.archlinux.org/index.php/X_KeyBoard_extension

(note: i haven't tried using xkb)

Mouse Extra Button Tools

How to set 5 buttons mouse?

apt-get install imwheel for config mouse buttons.

Bind Keys in Emacs

See: Emacs Keybinding, Keyboard, Articles Index.

Linux: Control Sound Level with Command Line

# increase sound level
amixer sset Master 8%+

# decrease sound level
amixer sset Master 8%-

# set to specific sound level
amixer sset Master 50%
# show a text gui mixer control panel
alsamixer scontrols

Misc

dumpkeys -l

blog comments powered by Disqus