Results 1 to 4 of 4

Thread: Pressing D

  1. #1

    Thread Starter
    Hyperactive Member Hampster's Avatar
    Join Date
    Feb 2001
    Location
    On my hamster wheel.
    Posts
    374

    Pressing D

    is there a way using code to simulate the user pressing D in another program besides the app?

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Here is one of the possible ways:
    VB Code:
    1. Const VK_H = 72
    2. Const VK_E = 69
    3. Const VK_L = 76
    4. Const VK_O = 79
    5. Const KEYEVENTF_EXTENDEDKEY = &H1
    6. Const KEYEVENTF_KEYUP = &H2
    7. Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    8. Private Sub Form_KeyPress(KeyAscii As Integer)
    9.     'Print the key on the form
    10.     Me.Print Chr$(KeyAscii);
    11. End Sub
    12. Private Sub Form_Paint()
    13.   'Clear the form
    14.     Me.Cls
    15.     keybd_event VK_H, 0, 0, 0   ' press H
    16.     keybd_event VK_H, 0, KEYEVENTF_KEYUP, 0   ' release H
    17.     keybd_event VK_E, 0, 0, 0  ' press E
    18.     keybd_event VK_E, 0, KEYEVENTF_KEYUP, 0  ' release E
    19.     keybd_event VK_L, 0, 0, 0  ' press L
    20.     keybd_event VK_L, 0, KEYEVENTF_KEYUP, 0  ' release L
    21.     keybd_event VK_L, 0, 0, 0  ' press L
    22.     keybd_event VK_L, 0, KEYEVENTF_KEYUP, 0  ' release L
    23.     keybd_event VK_O, 0, 0, 0  ' press O
    24.     keybd_event VK_O, 0, KEYEVENTF_KEYUP, 0  ' release O
    25. End Sub

    It is for other letters but just change them.
    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 Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Almost forgot. The contant for D is 68.
    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
    Matthew Gates
    Guest
    Try this:


    VB Code:
    1. Private Declare Function PostMessage Lib "user32" _
    2. Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
    3. ByVal wParam As Long, ByVal lParam As Long) As Long
    4.  
    5. Private Const WM_CHAR = &H102
    6.  
    7.  
    8. Private Sub Command1_Click()
    9.     PostMessage hwnd_of_app, WM_CHAR, vbKeyD, 0 'send D key
    10. 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