Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


Sending hotkeys via SendMessage


Sending hotkeys via SendMessage

Author
Message
Sweetve13
Sweetve13
Forum God
Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)

Group: Forum Members
Posts: 3, Visits: 8
I'm using sendmessage in vb.net to send keystrokes to another application that is not active (application runs in background thus not active). This part works just great. But I am not able to send hotkeys. Say for example. I'm sending keystrokes to notepad and I want the date. One can do this by clicking Edit>Time/Date or sending Alt then E then D. How could I achieve this? Thanks!

p.s. I've tried using WM_KEYDOWN, WM_KEYUP, WM_COMMAND to no avail. I'm sent the commands both to the handle for the specific control and the application itself (hwnd and x) and still no success.

This is what I'm using to send the keys so far (sending keys works, just not hotkeys):

Code:
VB.net:
--------------------------------------------------------------------------------
Private Declare Ansi Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpsz1 As String, ByVal lpsz2 As String) As Integer
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer

Public Const WM_CHAR = &H102

System.Diagnostics.Process.Start("C:WINNTsystem32notepad.exe")
Dim hwnd As Integer = FindWindow(vbNullString, "Untitled - NotePad")
Dim x As Integer = FindWindowEx(hwnd, 0, "Edit", vbNullString)
SendMessage(x, WM_CHAR, Keys.C, 0)
SendMessage(x, WM_CHAR, Keys.L, 0)



 

Sweetve13
Sweetve13
Forum God
Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)Forum God (1.1K reputation)

Group: Forum Members
Posts: 3, Visits: 8
I found an alternate way to do what I needed (select menu items). The code is as follows:

   [code=vb]  Private Declare Ansi Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer
    Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpsz1 As String, ByVal lpsz2 As String) As Integer
    Private Declare Function GetMenu Lib "user32" Alias "GetMenu" (ByVal hwnd As Integer) As Integer
    Private Declare Function GetSubMenu Lib "user32" Alias "GetSubMenu" (ByVal hMenu As Integer, ByVal nPos As Integer) As Integer
    Private Declare Function GetMenuItemID Lib "user32" Alias "GetMenuItemID" (ByVal hMenu As Integer, ByVal nPos As Integer) As Integer

    Private Const WM_COMMAND = &H111

        Dim hwnd, hWndMenu, hWndSubMenu, MenuItem As Integer
        hwnd = FindWindow(vbNullString, "Untitled - Notepad")
        hWndMenu = GetMenu(hwnd)                    ' Get handle to Menu Items
        hWndSubMenu = GetSubMenu(hWndMenu, 0)      ' Get handle to ‘File’ submenu
        MenuItem = GetMenuItemID(hWndSubMenu, 1)    ' Get menuID for the ‘Open’
        SendMessage(hwnd, WM_COMMAND, MenuItem, vbNullString)     ' Click ‘Open’ menuitem
[/code]

GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search