Results 1 to 3 of 3

Thread: How to Trap keybord on my computer

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2001
    Posts
    27

    How to Trap keybord on my computer

    Hi All,

    How can I trap keys pressed on my computer?

    Python

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    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       */
    }
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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
  •  



Click Here to Expand Forum to Full Width