|
-
Aug 30th, 2016, 01:41 AM
#1
Thread Starter
Banned
VB.NET SendMessage() KeyStrokes.
Hi,
I have opened the NotePad and I want to send key strokes using SendMessage. I have got parent and child window and tried to send keystrokes using SendMessage() but didn't work. Why ? As far as I know the code is correct.
PHP Code:
Const WM_KEYDOWN As Integer = &H100 Const WM_KEYUP As Int32 = &H101 Const VK_RETURN As Integer = &HD
Dim hWnd_notepad As IntPtr = FindWindow(Nothing, "Untitled - Notepad") Dim hWnd_notepad_class As IntPtr = FindWindowEx(hWnd_notepad, Nothing, "Edit", Nothing)
SendMessage(hWnd_notepad_class, WM_KEYDOWN, VK_RETURN, 0) SendMessage(hWnd_notepad_class, WM_KEYUP, VK_RETURN, 0)
Any help would be appreciated.
Thanks!
Last edited by abhishek009; Aug 30th, 2016 at 01:45 AM.
-
Aug 30th, 2016, 08:47 AM
#2
Junior Member
Re: VB.NET SendMessage() KeyStrokes.
-
Aug 30th, 2016, 09:41 AM
#3
Re: VB.NET SendMessage() KeyStrokes.
 Originally Posted by abhishek009
Hi,
I have opened the NotePad and I want to send key strokes using SendMessage. I have got parent and child window and tried to send keystrokes using SendMessage() but didn't work. Why ? As far as I know the code is correct.
FWIW, Testing on Win7 & 10 only here.
That code works in 7 but not in 10, tried using PostMessage instead and it works on both OS.
-
Aug 30th, 2016, 09:50 AM
#4
Thread Starter
Banned
Re: VB.NET SendMessage() KeyStrokes.
Actually I'm trying on the web browser control. I have a text box or text view on the control and want to send keystroke to it. PostMessage worked for NotePad. I have got the handler for the Web Browser control. Focused on the text element but it didn't send the text. Can you check if it's working for web browser too ?
Thanks !
P.S : I don't want to use SendKeys or HTML method to set the text.
-
Aug 30th, 2016, 10:52 AM
#5
Re: VB.NET SendMessage() KeyStrokes.
 Originally Posted by abhishek009
P.S : I don't want to use SendKeys or HTML method to set the text.
Quick test using html file (called SpellCheck) that is just a textbox and nothing else and this worked on Chrome browser, I never had any luck using APIs like this on browsers tho. You might want to try using UIAutomation, IIRC that can send stuff to browser elements. Good Luck!
Code:
Dim hWnd As IntPtr = FindWindow("Chrome_WidgetWin_1", "SpellCheck - Google Chrome")
If hWnd <> IntPtr.Zero Then
Dim HwndEdit As IntPtr = FindWindowEx(hWnd, IntPtr.Zero, "Chrome_RenderWidgetHostHWND", "Chrome Legacy Window")
If HwndEdit <> IntPtr.Zero Then
SetForegroundWindow(hWnd) ' bring chrome to foreground
' send return key
PostMessage(HwndEdit, WM_KEYDOWN, VK_RETURN, 0)
PostMessage(HwndEdit, WM_KEYUP, VK_RETURN, 0)
Else
MessageBox.Show("'Chrome_RenderWidgetHostHWND' not found!")
End If
Else
MessageBox.Show("'Chrome_WidgetWin_1' not found!")
End If
-
Aug 30th, 2016, 11:42 AM
#6
Thread Starter
Banned
Re: VB.NET SendMessage() KeyStrokes.
Thank you for your help. I have never heard of UIAutomation. Can you give me the link and documentation ? I searched on google but no luck.
Thanks again!
Tags for this Thread
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
|