Unix Programming - Detecting multiple keypresses

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > May 2004 > Detecting multiple keypresses





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Detecting multiple keypresses
kstahl

2004-05-12, 4:58 pm

Howdy,

I would like to get down to the nitty-gritty of the keyboard's operation.
Specifically, I would like to poll only a few keys on the keyboard, and I
would like to know when more than one key is pressed. In other words, I
would like to know how to access the keyboard's scan lines, so that if, for
example, the user is holding two of the arrow keys pressed simultaneously, I
will get a continuously changing response of Left-Right-Left-Right-and so
on. So far, all that comes to mind is scanf(), but this is clearly
inadequate.

Thanks for your help,
-Karl


Måns Rullgård

2004-05-12, 4:58 pm

"kstahl" <kstahl@stanford.edu> writes:

> Howdy,
>
> I would like to get down to the nitty-gritty of the keyboard's operation.
> Specifically, I would like to poll only a few keys on the keyboard, and I
> would like to know when more than one key is pressed. In other words, I
> would like to know how to access the keyboard's scan lines, so that if, for
> example, the user is holding two of the arrow keys pressed simultaneously, I
> will get a continuously changing response of Left-Right-Left-Right-and so
> on. So far, all that comes to mind is scanf(), but this is clearly
> inadequate.


I don't know a portable way to do it, but keep in mind that many
keyboards are unable to report all combinations of three or more
keys. Any two keys are usually fine.

--
Måns Rullgård
mru@kth.se
Fletcher Glenn

2004-05-12, 6:58 pm



kstahl wrote:
> Howdy,
>
> I would like to get down to the nitty-gritty of the keyboard's operation.
> Specifically, I would like to poll only a few keys on the keyboard, and I
> would like to know when more than one key is pressed. In other words, I
> would like to know how to access the keyboard's scan lines, so that if, for
> example, the user is holding two of the arrow keys pressed simultaneously, I
> will get a continuously changing response of Left-Right-Left-Right-and so
> on. So far, all that comes to mind is scanf(), but this is clearly
> inadequate.
>
> Thanks for your help,
> -Karl
>
>


I used to work in the keyboard business, and you have no guarantee that
any particular keyboard will work like any other. The differences
between keyboards are usually handled in the keyboard driver, but this
may vary from one system hardware vendor to another. The only guarantee
at the top level is that you will get keycodes. No guarantee is made as
to how those keycodes are presented, or in what order, especially under
the extreme situation of two or more keys pressed at the same time
(shift and or control keys excepted). Each keyboard vendor may have a
different method for handling these situations. Indeed, under the
general rule called "N-Key rollover", you will get the code of the
first key pressed, and not get any further codes until the first key
is released. From then on, you will only get key codes (in no
particular order) as each key is released until all keys have been
released. However, this rule may be implemented differently depending
on vendor.

Your only hope for continuity is if most of the vendors use the same
keyswitch technology and the same keyboard encoder chip.

--

Fletcher Glenn

Alex Sisson

2004-05-13, 5:34 am

"kstahl" <kstahl@stanford.edu> wrote in message news:<c7tv99$fh8$1@news.Stanford.EDU>...
> Howdy,
>
> I would like to get down to the nitty-gritty of the keyboard's operation.
> Specifically, I would like to poll only a few keys on the keyboard, and I
> would like to know when more than one key is pressed. In other words, I
> would like to know how to access the keyboard's scan lines, so that if, for
> example, the user is holding two of the arrow keys pressed simultaneously, I
> will get a continuously changing response of Left-Right-Left-Right-and so
> on. So far, all that comes to mind is scanf(), but this is clearly
> inadequate.
>
> Thanks for your help,
> -Karl


SDL may be able to help, as that is geared towards gaming. see http://libsdl.org.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com