How to know when a key from the keyboard is pressed ?
(PS: i cannot use the return key, just ONE key)
Thx in advance
How to know when a key from the keyboard is pressed ?
(PS: i cannot use the return key, just ONE key)
Thx in advance
OS and compiler?
I know you're new, but please try to give all relevant information when asking a question.
If you understand what you're doing, you're not learning anything.
sorry very much
Windows XP and Dev-C++(Mingw compiler)
look up the kbhit( ) function.. it is a boolean function that returns true whenever there is a keypress. It may be non-standard though but it works great.
- "Problem Solving C++, The Object of Programming" -Walter Savitch
- "Data Structures and Other Objects using C++" -Walter Savitch
- "Assembly Language for Intel-Based Computers" -Kip Irvine
- "Programming Windows, 5th edition" -Charles Petzold
- "Visual C++ MFC Programming by Example" -John E. Swanke
- "Network Programming Windows" -Jones/Ohlund
- "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
- "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel
Thx
I've tried this
while(!kbhit('c')) printf( "u didn't press c"); and it works
Does it work also for a combo like CTRL + Z ? If Yes, how ?
Last edited by delphi; 03-17-2005 at 04:43 PM.
Look at the kbhit() function again. It doesn't expect you to pass anything to it.
If you understand what you're doing, you're not learning anything.
good call.. i was hoping you'd notice
- "Problem Solving C++, The Object of Programming" -Walter Savitch
- "Data Structures and Other Objects using C++" -Walter Savitch
- "Assembly Language for Intel-Based Computers" -Kip Irvine
- "Programming Windows, 5th edition" -Charles Petzold
- "Visual C++ MFC Programming by Example" -John E. Swanke
- "Network Programming Windows" -Jones/Ohlund
- "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
- "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel
Part 5 of my Console Programming Tutorial covers keyboard events both blocking and non-blocking, and demonstrates techniques for trapping Alt etc.
The I/O is C++ style, but if you adjust the headers and replace the cout's with printf(), the example will work. The API routines are language neutral.
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.