|
-
May 5th, 2001, 04:09 AM
#1
Thread Starter
Junior Member
How to Trap keybord on my computer
Hi All,
How can I trap keys pressed on my computer?
-
May 5th, 2001, 10:19 AM
#2
Frenzied Member
What do you mean trap. If you mean getting them then use
Code:
_getch, _getche
Get a character from the console without echo (_getch) or with echo (_getche).
int _getch( void );
int _getche( void );
Routine Required Header Compatibility
_getch <conio.h> Win 95, Win NT
_getche <conio.h> Win 95, Win NT
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return Value
Both _getch and _getche return the character read. There is no error return.
Remarks
The _getch function reads a single character from the console without echoing. _getche reads a single character from the console and echoes the character read. Neither function can be used to read CTRL+C. When reading a function key or an arrow key, _getch and _getche must be called twice; the first call returns 0 or 0xE0, and the second call returns the actual key code.
Example
/* GETCH.C: This program reads characters from
* the keyboard until it receives a 'Y' or 'y'.
*/
#include <conio.h>
#include <ctype.h>
void main( void )
{
int ch;
_cputs( "Type 'Y' when finished typing keys: " );
do
{
ch = _getch();
ch = toupper( ch );
} while( ch != 'Y' );
_putch( ch );
_putch( '\r' ); /* Carriage return */
_putch( '\n' ); /* Line feed */
}
-
May 5th, 2001, 10:26 AM
#3
Frenzied Member
I could have sworn I already replied to this thread 
If you want to get the state of keys on the keyboard in a Windows app, you can get KeyDown messages just like the events in VB, or if you don't want to trap messages then you can just check if a key is down with the GetAsynchKeyState() function.
That's all Windows-specific, though.
Harry.
"From one thing, know ten thousand things."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|