if more than one key is down at the same time, how do you get both of them?
if more than one key is down at the same time, how do you get both of them?
depends on the operating system. MS-Windows: there is a WM_KEYDOWN message sent each time a key is pressed and WM_KEYUP when the key is released. shift, control and alt keys do not generate those events.
if you are using standard functions from stdio.h then just keep caling getch() until no more keys. How to tell when no more keys? There is no standard way to do that. If you compiler supports conio.h you might be able to use _kbhit() which returns 0 when nothing in the keyboard buffer.
Or you can use fgets() which will put everything up to the <Enter> into your buffer. Then you can check that buffer for each key.
Last edited by Ancient Dragon; 12-22-2005 at 10:32 AM.
getch() isn't standard, and besides, it's in <conio.h>. If you have getch(), you likely have kbhit() or _kbhit() too.if you are using standard functions from stdio.h then just keep caling getch() until no more keys. How to tell when no more keys? There is no standard way to do that. If you compiler supports conio.h you might be able to use _kbhit() which returns 0 when nothing in the keyboard buffer.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.