Detecting multiple keypresses

K

kstahl

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
 
J

Joona I Palaste

kstahl said:
I would like to get down to the nitty-gritty of the keyboard's
operation.

Can't be done in ISO standard C. Strictly speaking, you can't read the
keyboard at all in ISO standard C, merely the standard input stream.
Fortunately, most of the time there is a console handler reading the
keyboard and feeding the characters to the standard input stream. How it
does that is off-topic for comp.lang.c.

--
/-- Joona Palaste ([email protected]) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Remember: There are only three kinds of people - those who can count and those
who can't."
- Vampyra
 
K

kstahl

Thanks for your prompt response. I'm not familiar with "console handlers" -
can you recommend a newgroup/website where I might learn more about such
topics?
 
J

Joona I Palaste

kstahl said:
Thanks for your prompt response. I'm not familiar with "console handlers" -
can you recommend a newgroup/website where I might learn more about such
topics?

It depends on what operating system you are using. Here are a few
suggestions.
For MS Windows: comp.os.ms-windows.programmer
For Unix/Linux: comp.unix.programmer
 
N

Neil Kurzman

oona said:
Can't be done in ISO standard C. Strictly speaking, you can't read the
keyboard at all in ISO standard C, merely the standard input stream.
Fortunately, most of the time there is a console handler reading the
keyboard and feeding the characters to the standard input stream. How it
does that is off-topic for comp.lang.c.

--
/-- Joona Palaste ([email protected]) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Remember: There are only three kinds of people - those who can count and those
who can't."
- Vampyra

With PC hardware it is not possible. getch() will give you a Key and scan code.
There is no held down status.
 
T

Thomas Matthews

Neil said:
oona I Palaste wrote:




With PC hardware it is not possible. getch() will give you a Key and scan code.
There is no held down status.

Then how does Windows obtain the data for its key press messages?
Last time I looked, the Windows operating system could differentiate
between when a key was pressed and released.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
 
D

Dan Pop

In said:
Then how does Windows obtain the data for its key press messages?
Last time I looked, the Windows operating system could differentiate
between when a key was pressed and released.

IIRC (back in my MSDOS days I used to play with the keyboard interface of
the PC, but it's been 15 years ago...) the keyboard is "seen" as an 8-bit
port at some I/O address that "remembers" the last event received from
the keyboard. 7 bits are used for the scan code and 1 bit to indicate
whether the key was pressed or released.

Dan
 
A

Alan Balmer

Then how does Windows obtain the data for its key press messages?
Last time I looked, the Windows operating system could differentiate
between when a key was pressed and released.
There are separate scan codes for key down and key up. However, it's
*still* not topical here - take the discussion to some place like
comp.os.ms-windows.programmer, where the answers will be more
plentiful and more accurate.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top