Key Press and Release Events

Key Press and Release Events

Post by Michael B. Alle » Wed, 16 Jan 2002 19:54:00



I want to write a keyboard event module. I've initialized myself with the
standard terminos examples, but now I need to know how peek at scan codes
in the keyboard buffer.

If, for example, I depressed the left Alt key, followed by the Enter key,
and then released the Enter key and the Alt key I would like to be able to
fire four events for those four actions as they happen (or within some
reasonable amout of time (e.g. 100ms)) and I would like to do this without
modification to the Kernel.

Can someone point me in the right direction please?

Thanks,
Mike

 
 
 

Key Press and Release Events

Post by Floyd Davidso » Wed, 16 Jan 2002 20:55:41



Quote:>I want to write a keyboard event module. I've initialized myself with the
>standard terminos examples, but now I need to know how peek at scan codes
>in the keyboard buffer.

>If, for example, I depressed the left Alt key, followed by the Enter key,
>and then released the Enter key and the Alt key I would like to be able to
>fire four events for those four actions as they happen (or within some
>reasonable amout of time (e.g. 100ms)) and I would like to do this without
>modification to the Kernel.

>Can someone point me in the right direction please?

You want to look at the source code to _showkey(1)_, which is
part of the kbd-1.06.tar.gz package.  You can find it on most
any distribution site under linux/utils/kbd/.

--
Floyd L. Davidson         <http://www.ptialaska.net/~floyd>


 
 
 

Key Press and Release Events

Post by Michael B. Alle » Thu, 17 Jan 2002 05:57:35





>>I want to write a keyboard event module. I've initialized myself with
>>the standard terminos examples, but now I need to know how peek at scan
>>codes in the keyboard buffer.

>>If, for example, I depressed the left Alt key, followed by the Enter
>>key, and then released the Enter key and the Alt key I would like to be
>>able to fire four events for those four actions as they happen (or
>>within some reasonable amout of time (e.g. 100ms)) and I would like to
>>do this without modification to the Kernel.

>>Can someone point me in the right direction please?

> You want to look at the source code to _showkey(1)_, which is part of
> the kbd-1.06.tar.gz package.  You can find it on most any distribution
> site under linux/utils/kbd/.

Actually I saw that, but it looked like the technique didn't work in X.
I would like the module to be general purpose enought that it work in X
as well as on the console. Is there any way to do that or do I have to
detect that situation and use X code if connected to a pty?

Mike

 
 
 

Key Press and Release Events

Post by Floyd Davidso » Thu, 17 Jan 2002 12:42:54





>>>I want to write a keyboard event module. I've initialized myself with
>>>the standard terminos examples, but now I need to know how peek at scan
>>>codes in the keyboard buffer.

>>>If, for example, I depressed the left Alt key, followed by the Enter
>>>key, and then released the Enter key and the Alt key I would like to be
>>>able to fire four events for those four actions as they happen (or
>>>within some reasonable amout of time (e.g. 100ms)) and I would like to
>>>do this without modification to the Kernel.

>>>Can someone point me in the right direction please?

>> You want to look at the source code to _showkey(1)_, which is part of
>> the kbd-1.06.tar.gz package.  You can find it on most any distribution
>> site under linux/utils/kbd/.

>Actually I saw that, but it looked like the technique didn't work in X.
>I would like the module to be general purpose enought that it work in X
>as well as on the console. Is there any way to do that or do I have to
>detect that situation and use X code if connected to a pty?

You will certainly have to do it differently for X than for
any other terminal.

--
Floyd L. Davidson         <http://www.ptialaska.net/~floyd>

 
 
 

Key Press and Release Events

Post by Michael B. Alle » Thu, 17 Jan 2002 20:09:20



Quote:>>>>I want to write a keyboard event module.
<snip>
>>>>Can someone point me in the right direction please?

>>> You want to look at the source code to _showkey(1)_, which is part of
>>> the kbd-1.06.tar.gz package.  You can find it on most any distribution
>>> site under linux/utils/kbd/.

>>Actually I saw that, but it looked like the technique didn't work in X.
>>I would like the module to be general purpose enought that it work in X
>>as well as on the console. Is there any way to do that or do I have to
>>detect that situation and use X code if connected to a pty?

> You will certainly have to do it differently for X than for any other
> terminal.

Wow, this is getting ugly fast. I wonder if I can get the original
scancode from KeyPress and KeyRelease X events. Then I could mush them
down to the showkey equivalent io and normalize from there. I would also
like to support Putty so if I'm going to hack in support for key events
into it I might as well make the wire protocol as trivial as possible.
Provided I can negotite a keymap with Putty, I could support  the console
a la showkey, XTerm a la demoted X Key events, and Putty on Win32 a la
custom trivial networking protocol.

Wish me luck!
Mike

 
 
 

Key Press and Release Events

Post by George MacDonal » Fri, 18 Jan 2002 16:14:39




> >>>>I want to write a keyboard event module.
> <snip>
> >>>>Can someone point me in the right direction please?

> >>> You want to look at the source code to _showkey(1)_, which is part of
> >>> the kbd-1.06.tar.gz package.  You can find it on most any distribution
> >>> site under linux/utils/kbd/.

> >>Actually I saw that, but it looked like the technique didn't work in X.
> >>I would like the module to be general purpose enought that it work in X
> >>as well as on the console. Is there any way to do that or do I have to
> >>detect that situation and use X code if connected to a pty?

> > You will certainly have to do it differently for X than for any other
> > terminal.

> Wow, this is getting ugly fast. I wonder if I can get the original
> scancode from KeyPress and KeyRelease X events. Then I could mush them
> down to the showkey equivalent io and normalize from there. I would also
> like to support Putty so if I'm going to hack in support for key events
> into it I might as well make the wire protocol as trivial as possible.
> Provided I can negotite a keymap with Putty, I could support  the console
> a la showkey, XTerm a la demoted X Key events, and Putty on Win32 a la
> custom trivial networking protocol.

The purpose of X windows is to remove you from the hardware details,
such as things like scan codes! Ditto for the OS... The XKeyEvent
will tell you about key up/down events and the keycode used. Of
course X is a message passing client server architecture and running
on top of a fair share scheduler. Thus response times are not guaranteed...

Handling real time events is the job of the kernel.  If you want to
implement this sort of thing then do it there, if you want apps to
see scan codes, then make a /proc entry that can be polled or that
a process can go to sleep on waiting for a key stroke ... Or get a
small micro embedded system with no OS to do it. A basic stamp
would do nicely...

--
We stand on the shoulders of those giants who coded before.
Build a good layer, stand strong, and prepare for the next wave.
Guide those who come after you, give them your shoulder, lend them

 
 
 

Key Press and Release Events

Post by Michael B. Alle » Fri, 18 Jan 2002 17:45:13




>> Wow, this is getting ugly fast. I wonder if I can get the original
>> scancode from KeyPress and KeyRelease X events. Then I could mush them
>> down to the showkey equivalent io and normalize from there. I would
>> also like to support Putty so if I'm going to hack in support for key
>> events into it I might as well make the wire protocol as trivial as
>> possible. Provided I can negotite a keymap with Putty, I could support
>> the console a la showkey, XTerm a la demoted X Key events, and Putty on
>> Win32 a la custom trivial networking protocol.

> The purpose of X windows is to remove you from the hardware details,
> such as things like scan codes! Ditto for the OS... The XKeyEvent will
> tell you about key up/down events and the keycode used. Of course X is a
> message passing client server architecture and running on top of a fair
> share scheduler. Thus response times are not guaranteed...

> Handling real time events is the job of the kernel.  If you want to
> implement this sort of thing then do it there, if you want apps to see
> scan codes, then make a /proc entry that can be polled or that a process
> can go to sleep on waiting for a key stroke ... Or get a small micro
> embedded system with no OS to do it. A basic stamp would do nicely...

This doesn't help me with remote X clients and Putty. And I think there is
already work along these lines scheduled to go into 2.5.

I think what I have to do is introduce a new terminal io mode similar to
how an xterm can switch between ascii and utf-8 mode. It will be necessary
to hack the clients to interpret a funny sequence of bytes as an
instruction to switch into this new mode. The new mode is simply the
~(ICANON | ECHO) but with scancodes for both presses and releases. I
suppose the high-bit could indicate whether or not it's a press or
release.

Incedentally, the showkey example shows that the keycodes read from stdin
are only 7 bit values (the 8th bit is used to indicate press/release). How
are the upper 127 keys represented?

Mike

 
 
 

Key Press and Release Events

Post by George MacDonal » Sat, 19 Jan 2002 05:19:13





> >> Wow, this is getting ugly fast. I wonder if I can get the original
> >> scancode from KeyPress and KeyRelease X events. Then I could mush them
> >> down to the showkey equivalent io and normalize from there. I would
> >> also like to support Putty so if I'm going to hack in support for key
> >> events into it I might as well make the wire protocol as trivial as
> >> possible. Provided I can negotite a keymap with Putty, I could support
> >> the console a la showkey, XTerm a la demoted X Key events, and Putty on
> >> Win32 a la custom trivial networking protocol.

> > The purpose of X windows is to remove you from the hardware details,
> > such as things like scan codes! Ditto for the OS... The XKeyEvent will
> > tell you about key up/down events and the keycode used. Of course X is a
> > message passing client server architecture and running on top of a fair
> > share scheduler. Thus response times are not guaranteed...

> > Handling real time events is the job of the kernel.  If you want to
> > implement this sort of thing then do it there, if you want apps to see
> > scan codes, then make a /proc entry that can be polled or that a process
> > can go to sleep on waiting for a key stroke ... Or get a small micro
> > embedded system with no OS to do it. A basic stamp would do nicely...

> This doesn't help me with remote X clients and Putty. And I think there is
> already work along these lines scheduled to go into 2.5.

> I think what I have to do is introduce a new terminal io mode similar to
> how an xterm can switch between ascii and utf-8 mode. It will be necessary
> to hack the clients to interpret a funny sequence of bytes as an
> instruction to switch into this new mode. The new mode is simply the
> ~(ICANON | ECHO) but with scancodes for both presses and releases. I
> suppose the high-bit could indicate whether or not it's a press or
> release.

> Incedentally, the showkey example shows that the keycodes read from stdin
> are only 7 bit values (the 8th bit is used to indicate press/release). How
> are the upper 127 keys represented?

When do you think a key is "pressed"?

  When the user thinks so?

  When the key contacts close?

  When the keyboard scanner detects that closure?

  When the interrupt happens on the processor?

  When the key is handled by the interrupt routine?

  When the X system returns from the read and timestamps it?

  When an application gets it?

What do you set the timestamp to?

  Local time?

  GMT?

How do you ensure the clock is accurate?

What if the computer and keyboard are in different time zones?

What if the client is in a different time zone than the server?

--
We stand on the shoulders of those giants who coded before.
Build a good layer, stand strong, and prepare for the next wave.
Guide those who come after you, give them your shoulder, lend them

 
 
 

Key Press and Release Events

Post by Dave Blak » Sat, 19 Jan 2002 06:31:45



Quote:> > Wow, this is getting ugly fast. I wonder if I can get the original
> > scancode from KeyPress and KeyRelease X events.

...

Quote:>  The purpose of X windows is to remove you from the hardware details,
>  such as things like scan codes! Ditto for the OS... The XKeyEvent
>  will tell you about key up/down events and the keycode used.

Be sure to check out the source to /usr/X11R6/bin/xev.

--
Dave Blake

 
 
 

Key Press and Release Events

Post by Michael B. Alle » Sat, 19 Jan 2002 18:59:10


Quote:>> I think what I have to do is introduce a new terminal io mode similar
>> to how an xterm can switch between ascii and utf-8 mode. It will be
>> necessary to hack the clients to interpret a funny sequence of bytes as
>> an instruction to switch into this new mode. The new mode is simply the
>> ~(ICANON | ECHO) but with scancodes for both presses and releases. I
>> suppose the high-bit could indicate whether or not it's a press or
>> release.

>> Incedentally, the showkey example shows that the keycodes read from
>> stdin are only 7 bit values (the 8th bit is used to indicate
>> press/release). How are the upper 127 keys represented?

> What do you set the timestamp to?

I am not going to marshall *real* X events from the client to the server.
I'm going to hack XTerm and Putty to capture KeyEvents on their end and
send them to the server just like the normal cooked keyboard output for
feeding to the application's stdin. So the application will now read not
just one character per key but two. The high bit will be used to indicate
wheather or not it's a key press as opposed to a release. I'm basiclly
going to emulate the showkey mode on the client side. For XTerm this will
be a matter or finding the spot wher XTerm captures KeyEvents and feeds
them to the terminal emulation code. For Putty I will need to tap Win32
KeyEvents and do pretty much the same.

Of course I'm a totally newbie to Xlib programming  but it's usually a
good idea to have an excuse to learn something new before you do.

Mike