|
-
May 28th, 2006, 11:21 PM
#1
Thread Starter
Fanatic Member
Simulating keyboard
What do I best use to simulate keypresses to a window? Right now I'm using sendmessage and findwindowex to send keys to a certain class in a window, but the only thing I can get to work is WM_CHAR. If I want to simulate things like arrow presses, do I have to use keydown and keyup or syskey in succession? Thanks.
-
May 28th, 2006, 11:34 PM
#2
Re: Simulating keyboard
use keydown, keyup with the virtual keycode:
VB Code:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Const WM_KEYDOWN = &H100
Private Const WM_KEYUP = &H101
Private Const VK_LEFT = &H25
Private Const VK_UP = &H26
Private Const VK_RIGHT = &H27
Private Const VK_DOWN = &H28
Private Sub Command1_Click()
' Assuming lhWnd is the handle of the edit box or whatever
SendMessage lhWnd, WM_KEYDOWN, VK_LEFT, 1&
SendMessage lhWnd, WM_KEYUP, VK_LEFT, 1&
End Sub
There's also a keyb_event API, but you can only direct key presses to the app currently in focus
Last edited by bushmobile; May 28th, 2006 at 11:37 PM.
-
May 30th, 2006, 06:13 AM
#3
-
Jun 1st, 2006, 07:42 PM
#4
Member
Re: Simulating keyboard
Sometimes it is necessary to use Postmessage instead of Sendmessage, as well. Specifically with Vb.net. Don't ask me why.
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
|