[Y-devel] Key mappings

Bryce Nichols bryce at bnichols.org
Sat Feb 28 12:17:20 GMT 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Disclaimer: I wrote most of this before some of the more recent
 discussion, so some ideas are duplicates of or similar to what's been
 said already.  I still want to get my concept expressed, so I'm sending
 anyway!

There are two kinds of low-level key events: "press" and "release".  Now
what we want to get at the application level are symbols, perhaps with
some modifiers (shift, ctrl, meta, cmd, num_lock, caps_lock, whatever).

So an input event at the application level could be one of:

KeyPressEvent    <modifiers> <keysym>,
KeyReleaseEvent  <modifiers> <keysym>,
KeySymbolicEvent <modifiers> <keysym>,
KeyTypedEvent    <unicode character>

(Maybe the Symbolic and Typed events could be merged?)

KeySymbolic would be for denoting events such as YK_COPY, YK_CUT,
YK_PASTE, etc etc.  Any keyboard event with special semantic value,
really.  It won't correspond to a physical keypress in most cases, but
rather a sequence or combo.

The keymapping should map low-level key codes (corresponding to physical
key press events) into modifier state changes and key events.  The
<modifiers> field in an event, then, is just whatever the modifier state
was at the moment the event occurred.  It may also be helpful to have some
compose states that absorb multiple key code events and produces a single
key event (symbolic, or typed).  Essentially this compose state would be
a hidden modifier state with a stored key sequence.

A configuration might look something like the table below.  When a
physical key event occurs, the keymap table is used to look up the result.
The first matching entry (based on the key code and the current modifiers)
found is the one that's used.  (This implies that the ordering of some
entries may matter.)  When a match is found, the state change actions are
performed and the key events (if any) are sent.  State changes could be
the following:

set   <modifier>
unset <modifier>
set   <composition modifier>=<key_code_list>

where instead of <key_code_list> you could also have a function of a
composition modifier, such as:
    add( <modifier>, <code> )  # append a code to the modifier's code list
    removelast( <modifier> )   # remove the last code

This allows for multi-key actions.  The composition modifiers can be
matched based on the current content of their code list to get a mapping
from code sequences to symbolic events or unicode character
KeyTyped events.

Key codes should be represented by integers, but aliases can be used for
clarity.

Similarly, for modifiers and composition modifiers, aliases may be used.


######################################################################
#
# Example keyboard input config file
#

alias COMPOSE     = COMPOSE1 # internal composition modifier 1
alias ASCII       = COMPOSE2 #  and another
alias SHIFT       = MOD1        # first modifier
alias CTRL        = MOD2
alias NUM_LOCK    = MOD3
alias SUPER       = MOD4
alias SCROLL_LOCK = MOD5
alias CAPS_LOCK   = MOD6

alias a  = 65
alias b  = 66
 .
 .
 .
alias v = 118
 .
 .

alias RMETA = 309
alias ZERO = 256 #  key pad 0
alias ONE  = 257
alias TWO  = 258
 .
 .
 .
alias NINE = 265


action     | with modifiers   | state change           | key_event
- ------------------------------------------------------------------
press   1  |                  | set   SHIFT, L_SHIFT  | press YK_LSHIFT
release 1  | ~R_SHIFT         | unset SHIFT, L_SHIFT  | release YK_LSHIFT
press   2  |                  | set   SHIFT, R_SHIFT  | press YK_RSHIFT
release 2  | ~L_SHIFT         | unset SHIFT           | release YK_RSHIFT
press   3  | ~CAPS_LOCK       | set   CAPS_LOCK       | press YK_CAPS_LOCK
press   3  | CAPS_LOCK        | unset CAPS_LOCK       | press YK_CAPS_LOCK
release 3  |                  |                       | release YK_CAPS_LOCK
press   4  |                  | set   CTRL, L_CTRL    | press YK_LCTRL
release 4  | ~R_CTRL          | unset CTRL, L_CTRL    | release YK_LCTRL
release 4  | R_CTRL           |                       | release YK_LCTRL
press   5  |                  | set   CTRL, R_CTRL    | press YK_RCTRL
release 5  | ~L_CTRL          | unset CTRL, R_CTRL    | release YK_RCTRL
release 5  |                  | unset CTRL, R_CTRL    | release YK_RCTRL
press   6  |                  | set COMPOSE=[]        |
press   6  | COMPOSE=[]       | unset COMPOSE         |
press   6  | COMPOSE=         | unset COMPOSE         | type
              [c,o,p,y]                                  unicode(COPYRIGHT)
press   6  | COMPOSE=         | unset COMPOSE         | type
               [h,e,a,r,t]                               unicode(HEART)
press   a  | SHIFT ~CAPS_LOCK |                       | press YK_A
press   a  | ~SHIFT CAPS_LOCK |                       | press YK_A
release a  | COMPOSE          | set COMPOSE=          |
                                    add(COMPOSE, a)
release a  | SHIFT ~CAPS_LOCK |                       | release YK_A,
                                                        type unicode("A")
release a  | ~SHIFT CAPS_LOCK |                       | release YK_A,
                                                        type unicode("A")
press   a  |                  |                       | press YK_A
release a  |                  |                       | release YK_A,
                                                        type unicode("a")
 .
 . and so on and so forth
 .
#
# example paste symbolic event
#
press v    | CTRL             |                       | symbolic YK_PASTE

#
# input method for changing 3 digits to ascii
#
# to use, hold the compose key (RMETA, as it is here), type 3 digits,
# then release it
#
press RMETA  | ~ASCII          | ASCII=[]               |
press ZERO  | ASCII           | ASCII=add(ASCII, ZERO) |
press ONE   | ASCII           | ASCII=add(ASCII, ONE)  |
 .
 .
 .
press NINE  | ASCII           | ASCII=add(ASCII, NINE) |
release RMETA | ASCII=[ZERO,ZERO,ONE] | unset ASCII      | type YK_NUL
release RMETA | ASCII=[ZERO,ZERO,TWO] | unset ASCII      | type YK_SOH
 .
 .
 .
release RMETA  | ASCII=[ZERO,THREE,TWO] | unset ASCII     | type YK_SPACE
 .
 .
 .
# if there's no other ASCII match, leave ASCII mode:
release RMETA  | ASCII                  | unset ASCII     |
#
##########################################################################


How this all differs from Y as it is now:

1. The keymapping gets applied after determining modifier keys in Y.  You
   can't map F1 to YK_LSUPER for example.
2. The keymapping maps YKeyCode + modifiers to YKeyCode, as opposed
   to mapping low-level key sequences to key-events
3. No "Typed" events are generated in Y.
   Widgets only get:
     * the YKeyCode,
     * whether it's pressed or released, and
     * the modifier state.

The general scheme I've laid out here should allow a lot of flexibility in
creating input mappings.  With the flexibility though, comes the burden of
having to learn how the system works.  I think it would be possible,
however, to create a simplified mechanism for manipulating keymappings.
A nice GUI app may do the trick.  It could display the keymapping table in
a way that summarizes the content and allows the user to easily make
changes.  For example, symbolic events could be listed in a drop-down box,
so they could be selected to correspond to some key sequence.

- --Bryce

On Fri, 27 Feb 2004, Maurice van der Pot wrote:

> On Fri, Feb 27, 2004 at 09:42:12PM +0100, Rupert Mazzucco wrote:
> > On Fri, 27 Feb 2004, Maurice van der Pot wrote:
> >
> > > > The question is, how many "special keys" do we think
> > > > should be standardised?  There is quite a bunch of
> > > > non-alphanumeric keys on every modern keyboard, maybe
> > > > it would be better to use them for real "standards".
> > >
> > > I'm not sure what you mean with 'real "standards"', Rupert.
> >
> > It occurred to me that, while I voted for great flexibility on
> > a low level, I really only thought of remapping the alphanumeric
> > (and an. modified) keys.  There is a set of keys that probably
> > should never change their meaning, like modifiers, esc, ctrl,
> > function keys, return, backspace, begin/end, pause, print, pg up/down
> > etc., because they have a kind of meta-purpose.
>
> No matter the keymap, these keys would always stay the same, so
> there is no problem. If someone were to design a keymap that maps
> a greek alpha character on F1, that's fine by me. They still have the
> choice to map F1 function to another key or just not use it at all.
>
> > > I think that for each type of key there should be a unique
> > > identifying value (what is called a KeySym in X).
> >
> > (But that is only unique if the keymap doesn't change.  The
> > invariable identifier is the keycode.)
>
> You're right, I misused the word KeySym. What I meant was a value
> that is the same for the 'a' on azerty and on qwerty, but different
> for the 'alpha' even if the key that produces it is labeled with 'a'.
> In any case, the uniqueness I meant was that if a key press causes
> an event with this value (say 'alpha') that there can never be a
> situation where a key generates the same value but it actually means
> '$'.
>
> > > layouts for a moment, I'm pretty sure that if I were able to type
> > > fluently on both of them, I'd expect things to be bound to 'a' or
> > > 'q' no matter where they may be moved to by a change in keymap.
> >
> > Yes, but it seems that you are talking about switching keyboards,
> > not keymaps.
> >
> > I was thinking about eg switching from a latin to a greek keymap,
> > so that I would have "alpha" where there used to be "a".  What I
> > suggested was to write then "ctrl+alpha" in the menu where there
> > was "ctrl+a" before.
>
> If you want ctrl-a in your latin keymap to do the same as ctrl-alpha
> with the greek keymap, that is not a problem. What I am uncertain
> about is this:
> if you have a key k1 that with latin keymap generates character X and
> is bound to the paste action, what would you want to happen if with
> the greek keymap k2 produced the same character X?
> Would you want the shortcut to be triggered by pressing k2 or k1?
>
> > But obviously I wasn't thinking clearly, because this is nonsense.
> > There would still be written "a" on the key, and this is what counts.
> > There is, of course, the possibility of a pathological remapping that
> > moves the logical "a" to the physical "b" and vice versa.  Then
> > confusion would be complete.  Should probably be forbidden and enforced.
>
> So that means that if pressing 'q' is quit and I change my qwerty keymap
> to an azerty one, I suddenly have to press the key that produces an 'a'?
>
> > It seems to me now that the server needs to know, on the lowest level,
> > not only the available keycodes, but also what is actually printed on
> > the key that corresponds to a certain keycode (or, while we're at it,
> > make that a complete physical layout).  It would be quite annoying if,
> > after much keymap switching, an application for some control purpose
> > demanded pressing <some fancy unicode char> that the user can't actually
> > find on the board by looking at what's written on the keys!
>
> You will always need to be able to switch keymaps, so I can imagine you
> always have to use the same physical key to switch, but that is as far
> as I'm willing to go at the moment.
>
> Please try to convince me if you have a different opinion.
>
> Best regards,
> Maurice.
>
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
Comment: For info see https://quantumlab.net/pine_privacy_guard/

iD8DBQFAQIbRIT7jkoqrwXkRAmodAJ4lIGSBpSbbA6n5HF15f+uoQkG19gCZAcjl
Imlwuth8SVjd4akG9fvShQ8=
=WME9
-----END PGP SIGNATURE-----



More information about the Y-devel mailing list









2026 © www.Y-Windows.Org - All Rights Reserved