Simulate Mouse Click
Do you need something made? then ask in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
9 posts
Page 1 of 1
Ok, so is it possible to simulate mouse click on minimized window without changing it's window state ? I want to be able to "get" when user double clicks on app, save pointers location, and perform mouse click on that app without maximizing it for example 10secs every ?
if u open it and have it immediately click at the X,Y cord. then have it minimize might work. Since the code would be performed quickly if thats what you want. Otherwise im sure theres a way, maybe have some sort of code go in form load.
It would be easier to simulate the target event rather than the click, if the window must remain minimized.
If you are trying to click on a named control, you could use this:
Code: Select all
This will work in any window state. <DllImport("user32.dll")> Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
End Function
<DllImport("user32.dll")> Shared Function GetWindowText(ByVal hWnd As IntPtr, ByVal lpString As StringBuilder, ByVal nMaxCount As Integer) As Integer
End Function
Delegate Function del_EnumChildProc(ByVal hwnd As IntPtr, ByVal lParam As IntPtr) As Boolean
Const WM_LBUTTONDOWN As UInteger = &H201
Const WM_LBUTTONUP As UInteger = &H202
Function EnumChildProc(ByVal hwnd As IntPtr, ByVal lParam As IntPtr) As Boolean
Dim sb As StringBuilder = New StringBuilder(255)
GetWindowText(hwnd, sb, sb.MaxCapacity)
Dim text As String = sb.ToString()
If text = "1" Or text = "3" Then 'simulate a click down and up on the 1 and 3 buttons if they are found, lParam puts the coordinates at X:0, Y:0
SendMessage(hwnd, WM_LBUTTONDOWN, IntPtr.Zero, IntPtr.Zero)
SendMessage(hwnd, WM_LBUTTONUP, IntPtr.Zero, IntPtr.Zero)
End If
Return True
End Function
<DllImport("user32.dll")> Shared Function EnumChildWindows(ByVal hWndParent As IntPtr, ByVal lpEnumFunc As [Delegate], ByVal lParam As IntPtr) As Boolean
End Function
Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
Dim hwnd As IntPtr = Process.GetProcessesByName("calc")(0).MainWindowHandle 'windows calculator (example)
EnumChildWindows(hwnd, New del_EnumChildProc(AddressOf EnumChildProc), IntPtr.Zero)
End Sub
Last edited by mandai on Thu Mar 22, 2012 4:57 pm, edited 1 time in total.
Also, is there a way to "detect" clicked buttons name ? to read from api ? i am not that good ( i know 1%
) at using APIs
Or to perform click on Item From Coordinates ?

Or to perform click on Item From Coordinates ?
Ok, so i am messing with the code for an hour or two i think, and i still can't figure out how to double click item in listview on another app, i am figuring out, but nothing works, i even trying changing the X|Y coords of mouse click, but still nothing :/
EDIT : It is a listview ! not listbox
EDIT : It is a listview ! not listbox
You could detect a click with GetAsyncKeyState, you can then record information on the active window, cursor/window positions etc.
As of yet, I haven't come across a simple way to double click on a listview item while the window is minimized.
As of yet, I haven't come across a simple way to double click on a listview item while the window is minimized.
Ok, if you ever come into something like that, please let me know, i have been bumping my head for 6,7 hours last three days, searching for LVM_GETTEXT and i haven't found even 1 code that works :( Not even codes in C#
9 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023