I’ve been trying to type the character 1 in a notepad with focus using SendMessage and WM_KEYDOWN. I realize I can use SendKeys and other methods to accomplish this but I need to do this either using SendMessage or SendInput(which seems more complicated). I can’t get SendMessage to output the character and I was hoping someone could get me pointed in the right direction because it seems like it should be working. Thanks…
SendMessage:
[code]
#If TargetWindows
Declare Function SendMessageA Lib “User32” (hWnd As Integer, Msg As Integer, wParam As Integer, lParam As Integer) As Integer
Declare Function SendMessageW Lib “User32” (hWnd As Integer, Msg As Integer, wParam As Integer, lParam As Integer) As Integer
#If TargetWin32
If System.IsFunctionAvailable(“SendMessageW”, “User32”) Then
Return SendMessageW(hWnd, Msg, wParam, lParam)
Else
Return SendMessageA(hWnd, Msg, wParam, lParam)
End If
#EndIf
#EndIf[/code]
FindWindow:
[code]
#If TargetWindows
Soft Declare Function FindWindowA Lib “User32” (className As Integer, title As CString) As Integer
Soft Declare Function FindWindowW Lib “User32” (className As Integer, title As WString) As Integer
Dim handle As Integer
If System.IsFunctionAvailable(“FindWindowW”, “User32”) Then
handle = FindWindowW(0, title)
Else
handle = FindWindowA(0, title)
End If
If handle <> 0 Then
Declare Sub SetForegroundWindow Lib “User32” (hwnd As Integer)
Return Handle
else
Return -1
End If
#EndIf[/code]
Button Action:
[code]
Const VK_1 = &h31
Const WM_KEYDOWN = &H0100
Dim intMsg As Integer = SendMessage(FindWindow(“Untitled - Notepad”), WM_KEYDOWN, VK_1, 0)[/code]