Results 1 to 6 of 6

Thread: VB.NET SendMessage() KeyStrokes.

  1. #1

    Thread Starter
    Banned
    Join Date
    Jun 2014
    Location
    https://t.me/pump_upp
    Posts
    41

    Exclamation 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_notepadNothing"Edit"Nothing)


            
    SendMessage(hWnd_notepad_classWM_KEYDOWNVK_RETURN0)
            
    SendMessage(hWnd_notepad_classWM_KEYUPVK_RETURN0
    Any help would be appreciated.
    Thanks!
    Last edited by abhishek009; Aug 30th, 2016 at 01:45 AM.

  2. #2
    Junior Member
    Join Date
    Dec 2015
    Posts
    31

    Re: VB.NET SendMessage() KeyStrokes.


  3. #3
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: VB.NET SendMessage() KeyStrokes.

    Quote Originally Posted by abhishek009 View Post
    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.

  4. #4

    Thread Starter
    Banned
    Join Date
    Jun 2014
    Location
    https://t.me/pump_upp
    Posts
    41

    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.

  5. #5
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: VB.NET SendMessage() KeyStrokes.

    Quote Originally Posted by abhishek009 View Post
    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

  6. #6

    Thread Starter
    Banned
    Join Date
    Jun 2014
    Location
    https://t.me/pump_upp
    Posts
    41

    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
  •  



Click Here to Expand Forum to Full Width