Obijuan
Oct 20th, 2000, 09:41 AM
I am looking for a way to send keystrokes to another window. How can I do this? Any sample code?
Vlatko
Oct 20th, 2000, 11:54 AM
Have a look at this thread
http://www.vbforums.com/showthread.php?threadid=34222
enigmaICE
Oct 22nd, 2000, 01:17 PM
Declare Function FindWindow& Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String)
Declare Function FindWindowEx& Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String)
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const WM_SETTEXT = &HC
SendMessage Handle, WM_SETTEXT, 0, ByVal Form1.Text1.Text
First, you need to find the handle of the Edit Control you want to send the text to and thats where the FindWindow function comes in to play,( this function finds the appliaction you want to send the text to), next you must use the FindWindowEX to find the edit control in the that application once you have the edit control's handle you can send any string you want using the SendMessage Function.
I've included a sample program. just copy this code into a standard project file. put a textbox and a command button on form1
'copy this into your Module
Declare Function FindWindow& Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String)
Declare Function FindWindowEx& Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String)
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const WM_SETTEXT = &HC
Public Function SendTEXT()
Dim strString As String
Dim lParent As Long
lParent = FindWindow("Notepad", vbNullString)
Dim lChild1 As Long
lChild1 = FindWindowEx(lParent, 0, "Edit", vbNullString)
SendMessage lChild1, WM_SETTEXT, 0, ByVal Form1.Text1.Text
End Function
'copy this into form1
Private Sub Command1_Click()
Call SendTEXT
End Sub
Private Sub Form_Load()
Shell "C:\WINDOWS\NOTEPAD.EXE", vbNormalFocus
End Sub
I hope this helps and if you have any questions just email me. enigma676@home.com