none
Sending CONTROL-W to a chome tab with messages RRS feed

  • Question

  • Hi

    I want to send to a chrome tab a message with the keys CONTROL-W for close it.

    I have tested without success

    The code:

     Dim ps As Process
    
            For Each ps In Process.GetProcessesByName("chrome")
                If ps.MainWindowTitle <> "" Then
                    Debug.Print(ps.MainWindowTitle)
    
                    Debug.Print(SendMessageW(ps.MainWindowHandle, WM_KEYDOWN, VK_CONTROL, 0&))
                    Debug.Print(SendMessageW(ps.MainWindowHandle, WM_KEYDOWN, System.Windows.Forms.Keys.W, 0&))
                    Debug.Print(SendMessageW(ps.MainWindowHandle, WM_KEYUP, 87, 0&))
                    Debug.Print(SendMessageW(ps.MainWindowHandle, WM_KEYUP, System.Windows.Forms.Keys.W, 0&))
                 End If
            Next

    On the output windows i can see the tab title with ps.mainWindowTitle and is the right tab. But nothing occurs.

    I seen this can be done too with postmessage but i don't know how to do it.

    Can anyone give some help?

    Thanks in advance


    Saturday, June 17, 2017 10:23 AM

All replies

  • If you don't mind activating the window to foreground, you can use keybd_event()

    <DllImport("user32", EntryPoint:="keybd_event")>
        Public Shared Sub keybd_event(ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As UInteger, ByVal dwExtraInfo As UInteger)
        End Sub

    I tested on Windows 10 with Chrome (Chromium) Version 51.0.2683.0

    and it works.


    Saturday, June 17, 2017 1:58 PM