| | |
Send mouse click to only specified window
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2008
Posts: 1
Reputation:
Solved Threads: 0
I have a vb.net 2008 application that is supposed to send a mouse click to a specified window. This can be any window, and the user selects the correct one from a list box during configuration. The user can also change the window or the mouse button to click at any time.
Everything works fine, window selection, click interval, right or left button, etc. except for one thing. If I move the cursor out of the window, it will click at least one time on whatever window is under the cursor when the event fires, including the desktop.
I have an if statement that checks to see if the window under the cursor is the selected window before firing the mouse event, and it seems to work except for the first click after I leave the window. I call the mouse event based on the timer interval and then check for the correct window within the mouse click subroutine.
Here is the code that calls the timer, the timer, and the mouse click code. Why is it clicking outside the window?
If my code looks strange, I'm an old retired programmer from the days when CBASIC was the greatest thing to ever happen to BASIC. All this "Visual" stuff is anything but visual to me, but I'm learning.
Any help would be greatly appreciated.
Everything works fine, window selection, click interval, right or left button, etc. except for one thing. If I move the cursor out of the window, it will click at least one time on whatever window is under the cursor when the event fires, including the desktop.
I have an if statement that checks to see if the window under the cursor is the selected window before firing the mouse event, and it seems to work except for the first click after I leave the window. I call the mouse event based on the timer interval and then check for the correct window within the mouse click subroutine.
Here is the code that calls the timer, the timer, and the mouse click code. Why is it clicking outside the window?
VB.NET Syntax (Toggle Plain Text)
' ' Start the timer and start clicking ' ' numUpDown.Value is set by the user with a NumericUpDown control Timer1.Interval = numUpDown.Value * 1000 ' Timer runs in milliseconds Timer1.Enabled = True Private Sub Timer1_Tick( _ ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles Timer1.Tick ' ' Do not re-initialize blink timer if it ' is already running This timer is used to let the user ' know the click timer is running. ' If Timer2.Enabled = False Then Timer2.Interval = 1000 ' One second timer to blink Timer2.Enabled = True ' red and green End If ' strMouseAction is set by user to be "R" or "L" for mouse button Call subMouseClick(strMouseAction) Application.DoEvents() ' Allow for exit End Sub
VB.NET Syntax (Toggle Plain Text)
Public Sub subMouseClick(ByVal Action As String) Dim ptrFGWindow As IntPtr = GetForegroundWindow() Dim dwFlagsD As Int32 ' mouse button down Dim dwFlagsU As Int32 ' mouse button up ' ' Check to make sure the proper window is top window ' Do not send mouse clicks to undesired windows ' ' i64Handle is actually hWnd If i64Handle = ptrFGWindow Then Select Case Action Case "L" dwFlagsD = MOUSEEVENTF_LEFTDOWN dwFlagsU = MOUSEEVENTF_LEFTUP Case "R" dwFlagsD = MOUSEEVENTF_RIGHTDOWN dwFlagsU = MOUSEEVENTF_RIGHTUP End Select mouse_event(dwFlagsD, 0&, 0&, 0, 0) mouse_event(dwFlagsU, 0&, 0&, 0, 0) End If End Sub
Any help would be greatly appreciated.
•
•
Join Date: Oct 2009
Posts: 1
Reputation:
Solved Threads: 0
0
#2 Oct 13th, 2009
I am sorry, but it seems I dont fully understand your question:
You get the handle from the foregroundwindow (=ptrFGWindow) and compare it with the i64 handle, I assume this is the hwnd of you application window ?
Nevertheless your application can be in the foreground without the mouse beeing in the client area, so what is this going to prove ?
If you want to be absolutely sure the mouse pointer is inside the client area, you would have to call GetWindowInfo, check the windowsposition and compare it with the mouse position on the screen.
But as I said, I am not quite sure I understand the problem in full ...
You get the handle from the foregroundwindow (=ptrFGWindow) and compare it with the i64 handle, I assume this is the hwnd of you application window ?
Nevertheless your application can be in the foreground without the mouse beeing in the client area, so what is this going to prove ?
If you want to be absolutely sure the mouse pointer is inside the client area, you would have to call GetWindowInfo, check the windowsposition and compare it with the mouse position on the screen.
But as I said, I am not quite sure I understand the problem in full ...
![]() |
Similar Threads
- SpeedUp Your Window XP Never Than Before (Windows tips 'n' tweaks)
- explorer.exe uses 99% CPU (Viruses, Spyware and other Nasties)
- vb6 newbie needing some help (Visual Basic 4 / 5 / 6)
- Simulate Mouse Move (C++)
- How can i do that (Visual Basic 4 / 5 / 6)
- Obtain Remote Assistance by Sending an E-mail Message in Windows XP (Windows tips 'n' tweaks)
- Single Left clicking on a desktop icon tries to send ot to Recycling Bin? (Windows NT / 2000 / XP)
- Obtain Remote Assistance by Sending an E-mail Message in Windows XP (Windows tips 'n' tweaks)
- how to simulate mouse movement and click (C)
Other Threads in the VB.NET Forum
- Previous Thread: Refresh DataGridView
- Next Thread: VB.net 2008 Mobile Application FTP Upload
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2008 access add application arithmetic array assignment basic binary box button buttons center click code combo combobox component connectionstring convert cpu data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees excel exists firewall folder image images isnumericfuntioncall login math memory mobile module ms msaccess mssqlbackend mysql navigate net opacity pan peertopeervideostreaming picturebox picturebox1 port print printpreview problemwithinstallation project record regex reports" reuse right-to-left save savedialog search serial sorting sqldatbase storedprocedure string temp textbox timer txttoxmlconverter updown useraccounts usercontol usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vbnet view vista visual visualbasic visualbasic.net visualstudio web wpf xml





