in our Tcl/Tk application, we are sending key events ( and ) over a socket to a host application which handles the actual key events.
This usually works quite well, as we can relate any events to the corresponding event. For example on my German keyboard I can type the glyph € by pressing AltGr+e. This results in the following events:
| event | %k |
%A |
%K |
%N |
|---|---|---|---|---|
KeyPress |
108 |
(empty) | ISO_Level3_Shift |
65027 |
KeyPress |
26 |
€ |
€ |
8364 |
KeyRelease |
26 |
(empty) | e |
101 |
KeyRelease |
108 |
(empty) | ISO_Level3_Shift |
65027 |
As you can see, %A, %K and %N might expand to different values when pressing resp. releasing the e key, but %k is stable, so we can use this to detect which release event corresponds to which press event.
Unfortunately, we are hitting a hard wall with keyboard layouts that have dead keys: in this case we are unable to relate events to the event(s).
E.g. on a German keyboard (with dead keys), I can type the letter á by pressing ´-a.
When I bind all resp bind all to some logging function, I get the following events (in order):
| event | %k |
%A |
%K |
%N |
|---|---|---|---|---|
KeyRelease |
21 |
(empty) | ´ |
180 |
KeyPress |
0 |
á |
á |
225 |
KeyRelease |
38 |
(empty) | a |
97 |
the first thing to notice is that the dead key ´ does not produce a KeyPress event (only a KeyRelease event).
We can probably live with that, but what really baffles me is that when pressing the
a none of the bind-variables have an obvious relation between the two events.
How can I know that the key that was producing the letter á was released?
In a way that works across platforms (Linux, Darwin, Windows) and for unknown keyboard layouts (we've had complaints from French, Spanish and Portuguese people, but the community is really worldwide).