Jbob,
Ok, now I got it.. thanks..
You won't be able, in windows 2000/XP to send it directly using SendMessage as the message must be Translated, you'll need to use TranslateMessage instead.
The MSDN WM_KEYDOWN documentation states(see crefs below for reference):
"Windows 2000/XP: Applications must pass wParam to TranslateMessage without altering it at all." so I passed wParam off to TranslateMessage and It works just fine like this:
Declare Function TranslateMessage Lib "user32.dll" (ByRef lpMsg As MSG) As Integer
Public Structure MSG
Public hwnd As Integer
Public message As Integer
Public wParam As Integer
Public lParam As Integer
Public time As Integer
Public pt As Integer
End Structure
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim hwnd As Integer = FindWindow(vbNullString, "Untitled - NotePad") '/// assuming you have notepad open.
Dim x As Integer = FindWindowEx(hwnd, 0, "Edit", vbNullString)
Dim myMsg As MSG = New MSG
If Not x = 0 Then
myMsg.hwnd = x
myMsg.message = WM_KEYDOWN
myMsg.wParam = Keys.B
myMsg.lParam = 0
Dim ret As Integer
ret = TranslateMessage(myMsg)
Debug.WriteLine("TranslateMessage " & ret.ToString)
End If
End Sub
I believe you can code it anyway you like from here and put your "sleep" code in and it should work just fine, it is here.
cref:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput/keyboardinputreference/keyboardinputmessages/wm_keydown.asp
and
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/messagesandmessagequeues/messagesandmessagequeuesreference/messagesandmessagequeuesfunctions/translatemessage.asp
Hope this Helps you out, and If I can help you with anything else let me know.
progload
[Edited for missing functions]
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpsz1 As String, ByVal lpsz2 As String) As Integer