Results 1 to 4 of 4

Thread: How to simulate a key press???

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2001
    Posts
    2

    Question How to simulate a key press???

    I would like to know if someone could please tell me how to simulate a keyboard key press by API.

    Thank you in advance.

  2. #2
    Member
    Join Date
    Apr 2001
    Posts
    35
    You don't neccessarily need an API call - try:

    SendKeys "t"
    SendKeys "hello world"
    SendKeys "{TAB}"
    SendKeys "{ENTER}"

    SendKeys follows the form:

    Code:
    SendKeys string [,wait As Boolean]
    so if you want to wait for the last key to be pressed before simulating another one, try:

    SendKeys "{DEL}", True

    Hope this helps!

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2001
    Posts
    2
    thank you very much, but I need the API because i am going to "convert" a joystick button signal to a keyboard key so I will need to use the keyup and keydown. The only possible way to do so is by API

  4. #4
    Matthew Gates
    Guest
    Use the keybd_event API function.


    VB Code:
    1. Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As _
    2. Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal _
    3. dwExtraInfo As Long)
    4.  
    5. Private Const KEYEVENTF_KEYUP = &H2
    6.  
    7.  
    8. Private Sub Command1_Click()
    9.     Text1.SetFocus
    10.     keybd_event vbKeyH, 0, 0, 0  
    11.     keybd_event vbKeyH, 0, KEYEVENTF_KEYUP, 0
    12.     keybd_event vbKeyE, 0, 0, 0  
    13.     keybd_event vbKeyE, 0, KEYEVENTF_KEYUP, 0
    14.     keybd_event vbKeyL, 0, 0, 0  
    15.     keybd_event vbKeyL, 0, KEYEVENTF_KEYUP, 0
    16.     keybd_event vbKeyL, 0, 0, 0  
    17.     keybd_event vbKeyL, 0, KEYEVENTF_KEYUP, 0
    18.     keybd_event vbKeyO, 0, 0, 0  
    19.     keybd_event vbKeyO, 0, KEYEVENTF_KEYUP, 0
    20. End Sub

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