Vital part of my keyboard config.
Go to file
David Shepherd b1f0a0601b Change to using KeySyms rather than keycodes to store to-keys
Modify all code to store and manipulate KeySyms instead of KeyCodes for
output key data.

Incomplete in two places (both also noted by comments in the code):

* When creating the additional key press events I have not yet implemented
  the switch to using `XSendEvent` rather than `XTestFakeKeyEvent`. Instead
  I just convert back to a keycode assuming zero shift level and
  group. This gives the same behaviour as before.

* When checking that an event is not one that we generated I haven't managed
  to figure out how to get the keysym of the event from the data provided
  by X. Instead I compare the key codes for now, which will work until the
  above issue is fixed.
2013-09-25 00:36:30 +01:00
.gitignore Added gitignore 2013-01-31 17:31:54 -08:00
LICENSE First commit 2012-03-31 23:02:17 +02:00
Makefile Fix Makefile for BSD make 2012-10-15 00:19:52 +04:00
README.md Readme: minor cleanup 2013-05-14 13:00:56 +02:00
xcape.c Change to using KeySyms rather than keycodes to store to-keys 2013-09-25 00:36:30 +01:00

XCAPE

xcape allows you to use a modifier key as another key when pressed and released on its own. Note that it is slightly slower than pressing the original key, because the pressed event does not occur until the key is released. The default behaviour is to generate the Escape key when Left Control is pressed and released on its own. (If you don't understand why anybody would want this, I'm guessing that Vim is not your favourite text editor ;)

Minimal building instructions

$ sudo apt-get install git gcc make libx11-dev libxtst-dev pkg-config
$ mkdir xcape
$ cd xcape
$ git clone https://github.com/alols/xcape.git .
$ make

Usage

$ xcape [-d] [-t <timeout ms>] [-e <map-expression>]

-d

Debug mode. Does not fork into the background.

-t <timeout ms>

If you hold a key longer than this timeout, xcape will not generate a key event. Default is 50 ms.

-e <map-expression>

The expression has the grammar 'ModKey=Key[|OtherKey][;NextExpression]'

The list of key names is found in the header file X11/keysymdef.h (remove the XK_ prefix).

Alternatively, you can specify ModKey in decimal (prefix #), octal (#0), or hexadecimal (#0x). It will be interpreted as a keycode unless no corresponding key name is found.

Examples

  1. This will make Left Shift generate Escape when pressed and released on it's own, and Left Control generate Ctrl-O combination when pressed and released on it's own.

    xcape -e 'Shift_L=Escape;Control_L=Control_L|O'

  2. If your s key has the code 42 and your l key 43 and you have set both to AltGr (a.k.a. ISO_Level3_Shift) with xmodmap, then this will generate the ordinary letters when pressed and released on their own. But pressed together with another key, the s or l key will produce AltGr. So, depending on your keyboard layout, you can compose e.g. @, { or ³ easily when touch-typing.

    xcape -e '#42=s;#43=l'

Note regarding xmodmap

If you are in the habit of remapping keycodes to keysyms (eg, using xmodmap), there are two issues you may encounter.

  1. You will need to restart xcape after every time you modify the mapping from keycodes to keysyms (eg, with xmodmap), or xcape will still use the old mapping.

  2. The key you wish to send must have a defined keycode. So for example, with the default mapping Control_L=Escape, you still need an escape key defined in your xmodmap mapping. (I get around this by using 255, which my keyboard cannot send).

Contact

Find the latest version at https://github.com/alols/xcape

The author can be reached at albin dot olsson at gmail dot com