Re: Help writing device driver

From: Grant Edwards (grante_at_visi.com)
Date: 08/22/05


Date: Mon, 22 Aug 2005 21:14:32 -0000

On 2005-08-22, michaelmossey@yahoo.com <michaelmossey@yahoo.com> wrote:

>> X11 already deals with chords: a chord consists of zero or
>> more chording (aka "modifier") keys (e.g. shift, alt, ctrl, or
>> meta) and exactly one non-modifier key.
>
> Right. But I want to make "chords" out of multiple
> non-modifier keys.

No problem. The concept of "modifier" vs. "non-modifier" is
implemented in the X11 keyboard driver, not in the keyboard.

> The keyboard isn't designed to do this;

Isn't designed to do what? The keyboard sends key-down events
as the keys are pressed and key-up events when the keys are
released. That's all. What the key-down/key-up events mean is
up to software.

> but it turns out that several keyboards I tried behave
> sensibly when you push and hold several (non-modifier) keys at
> once: they transmit the keys in rapid sequence.

That's because there is no such thing as "at once". The
keyboard is run by a microprocessor and communicates through a
serial interface. It has to send the key-up/down events one at
a time in the order it detects them. What appears on the
screen after you've done that is a result of how the SW you're
running decided to interpret the key-down and key-up events
from the keys you pressed.

> At least, in X11 (and in Windows XP) when I'm in an app, I see a
> cluster of all the keys I pressed, not necessarily in a fixed order.

Right.

>>> It might not be able to track key releases.
>>
>> It does now.
>
> Right. I'm talking about when you hold multiple non-modifier
> keys: the release behavior might not be what I want. What I
> want is for each key to transmit release when it is truly
> released,

That's what it _does_ do. Here's output from the "xev" program
that shows the events received from the keyboard when I
"chorded" four keys: A+S+D+F:

KeyPress event, serial 27, synthetic NO, window 0x1e00001,
    root 0x46, subw 0x0, time 8084531, (34,128), root:(1040,158),
    state 0x0, keycode 41 (keysym 0x66, f), same_screen YES,
    XLookupString gives 1 bytes: (66) "f"
    XmbLookupString gives 1 bytes: (66) "f"
    XFilterEvent returns: False

KeyPress event, serial 30, synthetic NO, window 0x1e00001,
    root 0x46, subw 0x0, time 8084568, (34,128), root:(1040,158),
    state 0x0, keycode 38 (keysym 0x61, a), same_screen YES,
    XLookupString gives 1 bytes: (61) "a"
    XmbLookupString gives 1 bytes: (61) "a"
    XFilterEvent returns: False

KeyPress event, serial 30, synthetic NO, window 0x1e00001,
    root 0x46, subw 0x0, time 8084571, (34,128), root:(1040,158),
    state 0x0, keycode 40 (keysym 0x64, d), same_screen YES,
    XLookupString gives 1 bytes: (64) "d"
    XmbLookupString gives 1 bytes: (64) "d"
    XFilterEvent returns: False

KeyPress event, serial 30, synthetic NO, window 0x1e00001,
    root 0x46, subw 0x0, time 8084608, (34,128), root:(1040,158),
    state 0x0, keycode 39 (keysym 0x73, s), same_screen YES,
    XLookupString gives 1 bytes: (73) "s"
    XmbLookupString gives 1 bytes: (73) "s"
    XFilterEvent returns: False

KeyRelease event, serial 30, synthetic NO, window 0x1e00001,
    root 0x46, subw 0x0, time 8084842, (34,128), root:(1040,158),
    state 0x0, keycode 38 (keysym 0x61, a), same_screen YES,
    XLookupString gives 1 bytes: (61) "a"

KeyRelease event, serial 30, synthetic NO, window 0x1e00001,
    root 0x46, subw 0x0, time 8084883, (34,128), root:(1040,158),
    state 0x0, keycode 41 (keysym 0x66, f), same_screen YES,
    XLookupString gives 1 bytes: (66) "f"

KeyRelease event, serial 30, synthetic NO, window 0x1e00001,
    root 0x46, subw 0x0, time 8084926, (34,128), root:(1040,158),
    state 0x0, keycode 39 (keysym 0x73, s), same_screen YES,
    XLookupString gives 1 bytes: (73) "s"

KeyRelease event, serial 30, synthetic NO, window 0x1e00001,
    root 0x46, subw 0x0, time 8084932, (34,128), root:(1040,158),
    state 0x0, keycode 40 (keysym 0x64, d), same_screen YES,
    XLookupString gives 1 bytes: (64) "d"

Note that all four key-down events appeared temporally close
together -- I don't know what the timestamp units are, but the
key down events all happend withing about 30 ticks of each
other. About 300 ticks later, the key-up events arrive, and
they're all within about 90 ticks of each other. Apparently
I'm a little sloppy on my simultaneous key releasing.
    
> but since the keyboard is not designed to do that with
> multiple non-modifier keys held,

The keyboard is designed to do that. It already does that.

> I'm just saying I don't know what its behavior will be.

I'm just saying I do know what it's behavior will be: every key
sends a key-down event when it's pressed, and a key-up event
when it's released.

>>> Doing everything in Emacs lisp is almost a solution, but I
>>> would prefer to have an OS driver.
>>
>> Though it's similar in some ways, an X11 driver isn't really an
>> OS driver. That means the place to ask about such a thing is
>> probably in an X.org development list http://www.x.org/.
>
> Oh.. okay. Thanks for the tip.

-- 
Grant Edwards                   grante             Yow!  -- I love KATRINKA
                                  at               because she drives a
                               visi.com            PONTIAC. We're going
                                                   awaynow. I fed the cat.


Relevant Pages

  • Re: Unhappy Xorg upgrade
    ... The bogus keyboard scans. ... I press the keys "TAB q w" over an `xev' window and see the bogus ... HAL-less mode. ...
    (freebsd-stable)
  • Re: Keyboard test page updated
    ... Keyboard handling is one of the hardest cross-browser issues. ... Looks good to me at this point, having tested numerous browsers ... Control or Meta keys). ... keypress events on keydown after sniffing out certain browsers (e.g. ...
    (comp.lang.javascript)
  • Re: To yay, or not to yay...
    ... keys of this keyboard so, technically, I could reach his mobile in a ... of the first bunch, I'm in a team working on code from one, and need ... don't hurt themselves when they jump out the window. ...
    (alt.sysadmin.recovery)
  • Linux problems with USB HID keyboards and patches
    ... Navigator USB connected keyboard. ... page 0x7, usage 0xe5, code 54 ... The mapping of HID keys to event keys and from event keys ...
    (Linux-Kernel)
  • Re: Great SWT Program
    ... issues of environment input options vs. individual application input ... One trivial example would be a 100-key keyboard where ... The number of keys and the force needed are orthogonal, ...
    (comp.lang.java.programmer)