Results 1 to 8 of 8

Thread: Simulate Keypress

  1. #1

    Thread Starter
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340
    How can i simulate a key press, in the console window? Preferably not using MFC or API, if possible, but if not thats ok.

    Thanks

  2. #2
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Use the keybd_event API function will do.

  3. #3
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    In case you don't have the documantetion:
    Code:
    keybd_event
    The keybd_event function synthesizes a keystroke. The system can use such a synthesized keystroke to generate a WM_KEYUP or WM_KEYDOWN message. The keyboard driver's interrupt handler calls the keybd_event function. 
    
    Windows NT: This function has been superseded. Use SendInput instead.
    
    VOID keybd_event(
      BYTE bVk,           // virtual-key code
      BYTE bScan,         // hardware scan code
      DWORD dwFlags,      // flags specifying various function options
      DWORD dwExtraInfo   // additional data associated with keystroke
    );
     
    Parameters
    bVk 
    Specifies a virtual-key code. The code must be a value in the range 1 to 254. 
    bScan 
    Specifies a hardware scan code for the key. 
    dwFlags 
    A set of flag bits that specify various aspects of function operation. An application can use any combination of the following predefined constant values to set the flags. Value Meaning 
    KEYEVENTF_EXTENDEDKEY If specified, the scan code was preceded by a prefix byte having the value 0xE0 (224). 
    KEYEVENTF_KEYUP If specified, the key is being released. If not specified, the key is being depressed. 
    
    
    dwExtraInfo 
    Specifies an additional 32-bit value associated with the key stroke. 
    Return Values
    This function has no return value. 
    
    Remarks
    Although keybd_event passes an OEM-dependent hardware scan code to the system, applications should not use the scan code. The system converts scan codes to virtual-key codes internally and clears the up/down bit in the scan code before passing it to applications. 
    
    An application can simulate a press of the PRINTSCREEN key in order to obtain a screen snapshot and save it to the clipboard. To do this, call keybd_event with the bVk parameter set to VK_SNAPSHOT, and the bScan parameter set to 0 for a snapshot of the full screen or set bScan to 1 for a snapshot of the active window.
    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

  4. #4
    Guest
    You can also use PostMessage to send the WM_CHAR message.

  5. #5

    Thread Starter
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340
    vlatko, is that documentation from the MSDN library? If it is, do you know where i can get the latest version? Maybe i could anwser some of my own questions then. If it isin't from MSDN, could you tell me where to get it?

  6. #6
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    I think it from MSDN too. Juz in case you need the lastest MSDN reference you can always goto the MSDN Online Library

  7. #7

    Thread Starter
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340
    well is that the full MSDN library? i thought that you had to subscribe to it or something?

  8. #8

    Thread Starter
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340
    oh, stupid me, maybe i should read the site before i ask a question..

    haha

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