473,728 Members | 1,454 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simulate Mouse Click Without Focus

Is it possible to simulate a mouse click in the window I made (it's a
Form), but not give it focus?

I tried using WinAPI's mouseevent and SendMessage of
WM_LBUTTONDOWN/WM_LBUTTONUP as suggested by the folks in #winapi on
EFnet, but I think those require the window to have focus. Either that,
or I'm doing something else wrong. The click actually seems to work
once, and then stops working... I have no idea what is the problem
actually. How do I go about debugging this? I tried using SetPixel to
draw where it was simulating a click but I don't see anything drawn...

Thanks for reading.

Dec 11 '06 #1
18 22102
Just call the method.

Cor

<el***********@ gmail.comschree f in bericht
news:11******** **************@ f1g2000cwa.goog legroups.com...
Is it possible to simulate a mouse click in the window I made (it's a
Form), but not give it focus?

I tried using WinAPI's mouseevent and SendMessage of
WM_LBUTTONDOWN/WM_LBUTTONUP as suggested by the folks in #winapi on
EFnet, but I think those require the window to have focus. Either that,
or I'm doing something else wrong. The click actually seems to work
once, and then stops working... I have no idea what is the problem
actually. How do I go about debugging this? I tried using SetPixel to
draw where it was simulating a click but I don't see anything drawn...

Thanks for reading.

Dec 11 '06 #2
I don't understand. Call which method?

Cor Ligthert [MVP] wrote:
Just call the method.

Cor

<el***********@ gmail.comschree f in bericht
news:11******** **************@ f1g2000cwa.goog legroups.com...
Is it possible to simulate a mouse click in the window I made (it's a
Form), but not give it focus?

I tried using WinAPI's mouseevent and SendMessage of
WM_LBUTTONDOWN/WM_LBUTTONUP as suggested by the folks in #winapi on
EFnet, but I think those require the window to have focus. Either that,
or I'm doing something else wrong. The click actually seems to work
once, and then stops working... I have no idea what is the problem
actually. How do I go about debugging this? I tried using SetPixel to
draw where it was simulating a click but I don't see anything drawn...

Thanks for reading.
Dec 11 '06 #3
okay, I think I understand - you mean the method for the Form. I get
it.

However, I don't have the source code to that form. it's just an .exe

What can I do now?

eliss.carm...@g mail.com wrote:
I don't understand. Call which method?

Cor Ligthert [MVP] wrote:
Just call the method.

Cor

<el***********@ gmail.comschree f in bericht
news:11******** **************@ f1g2000cwa.goog legroups.com...
Is it possible to simulate a mouse click in the window I made (it's a
Form), but not give it focus?
>
I tried using WinAPI's mouseevent and SendMessage of
WM_LBUTTONDOWN/WM_LBUTTONUP as suggested by the folks in #winapi on
EFnet, but I think those require the window to have focus. Either that,
or I'm doing something else wrong. The click actually seems to work
once, and then stops working... I have no idea what is the problem
actually. How do I go about debugging this? I tried using SetPixel to
draw where it was simulating a click but I don't see anything drawn...
>
Thanks for reading.
>
Dec 11 '06 #4
WhatIWantToDo(n ull,null)
<el***********@ gmail.comschree f in bericht
news:11******** **************@ 80g2000cwy.goog legroups.com...
>I don't understand. Call which method?

Cor Ligthert [MVP] wrote:
>Just call the method.

Cor

<el*********** @gmail.comschre ef in bericht
news:11******* *************** @f1g2000cwa.goo glegroups.com.. .
Is it possible to simulate a mouse click in the window I made (it's a
Form), but not give it focus?

I tried using WinAPI's mouseevent and SendMessage of
WM_LBUTTONDOWN/WM_LBUTTONUP as suggested by the folks in #winapi on
EFnet, but I think those require the window to have focus. Either that,
or I'm doing something else wrong. The click actually seems to work
once, and then stops working... I have no idea what is the problem
actually. How do I go about debugging this? I tried using SetPixel to
draw where it was simulating a click but I don't see anything drawn...

Thanks for reading.

Dec 11 '06 #5
<el***********@ gmail.comwrote in message
news:11******** **************@ j44g2000cwa.goo glegroups.com.. .
okay, I think I understand - you mean the method for the Form. I get
it.

However, I don't have the source code to that form. it's just an .exe

What can I do now?
I'm not sure if the form requires focus. Most apps won't require the focus
afaik but maybe windows does some checks before sending the message. Use
spy++ on the button/form in question and see what message it is receiving.
Have a look to see how this varies if you really do click it.

Michael
Dec 11 '06 #6
I checked with spy++ and it said it was receiving a wm_lbuttondown and
wm_lbuttonup at a location. But I don't know where that location is...
how do I know if it's the right place? Also, only one click works (the
first one) and then clicks do nothing. How can I debug it?

Michael C wrote:
<el***********@ gmail.comwrote in message
news:11******** **************@ j44g2000cwa.goo glegroups.com.. .
okay, I think I understand - you mean the method for the Form. I get
it.

However, I don't have the source code to that form. it's just an .exe

What can I do now?

I'm not sure if the form requires focus. Most apps won't require the focus
afaik but maybe windows does some checks before sending the message. Use
spy++ on the button/form in question and see what message it is receiving.
Have a look to see how this varies if you really do click it.

Michael
Dec 11 '06 #7
el***********@g mail.com wrote:
>However, I don't have the source code to that form. it's just an .exe
I don't understand. You said it's a window that *you made*. How did
you make it? Why don't you have the source code?

And what *exactly* are you trying to do? Spoof a click on a button? Or
on some other part of the form?

If it's for a button, I think it's better to use WM_COMMAND send to
the form itself. Look that up in MSDN to figure out what parameters to
use.

--
Lucian
Dec 11 '06 #8
It might not be a button. that's the thing. It could be a menu, or
textbox, or just a part of the window.

I made it, meaning I Executed it. It's another application. For
example, like I execute calc.exe

Thanks

Lucian Wischik wrote:
el***********@g mail.com wrote:
However, I don't have the source code to that form. it's just an .exe

I don't understand. You said it's a window that *you made*. How did
you make it? Why don't you have the source code?

And what *exactly* are you trying to do? Spoof a click on a button? Or
on some other part of the form?

If it's for a button, I think it's better to use WM_COMMAND send to
the form itself. Look that up in MSDN to figure out what parameters to
use.

--
Lucian
Dec 11 '06 #9
el***********@g mail.com wrote:
>It might not be a button. that's the thing. It could be a menu, or
textbox, or just a part of the window.
We can't give you a general answer. Every application can be written
to respond to messages however it sees fit. Some applications may
choose to respond to WM_LBUTTONDOWN only if they have focus. Other
applications may choose to respond to WM_LBUTTONUP only if they're on
the right hand half of the screen.

All that will guide you here are (1) extensive familiarity with how
applications typically handle win32 messages, (2) specific
experimentation with particular parts of these applications that
you're trying to control.

Without telling us (2), those of us who know (1) can't help at all!

I have to say that it's rare for focus to be an issue in handling
WM_LBUTTONDOWN or WM_LBUTTONUP, so the problem is elsewhere. Sometimes
application's don't like receiving the two messages in rapid
succession. You might consider putting a Sleep(500) delay and see if
it works.

For parts of windows, some applications will require appropriate
WM_MOUSEMOVEs to have come. And menus are a complete black art to me!

Really, everything you do has to proceed by gradual experimentation .
If you're going to be trying to control many different types of
applications ("buttons, menus, textboxes, parts of windows") then you
might consider investing your time in a "experiment er's toolbox" --
write an application that lets you interactively send messages to
other apps, without having to recompile/rerun all the time.

--
Lucian
Dec 11 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2296
by: Ryan Liu | last post by:
Can someone give a sample to prevent a row from being deleted in a datatable? I tried e.Row.RejectChanges(); in dt_RowDeleting() but seems does not work. I need verify if there other data using data in this row before actually remove it from datagrid. I can certainly control with Delete button. But if I want to allow the user to use Del key on the keyboard, I lost this kind control.
3
6157
by: Glenn Palomar | last post by:
Hi, Instead of using user32 API for simulating mouse click (left down, left up, etc.), are there any .net function/class that i can use? Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Int32, ByVal dx As Int32, ByVal dy As Int32, ByVal cButtons As Int32, ByVal dwExtraInfo As Int32) Thanks,
3
34820
by: madhuri.eerupula | last post by:
Hi. How to simulate(automatic) mouse movements and click operation using c#. Actually, i got pixels in the face (face tracking) right now and i need to move mouse(automatically, without using mouse manually) i.e., simulate mouse click operation using those pixels in c#. I think we can use robot() class in java , to achieve this, but how can we do this using c#. Hope you understand my problem and get bck to me asap. thanx bye
4
5493
by: Abhishek | last post by:
Hi, I have a activex web browser embedded in a windows form and on a click of a form button i need the mouse to go the position for example 100, 100 and click the link that will be there on that position. i am usind the win api setcursonpos to set the mouse position assume that the link will always be there at 100, 100. how do i get Windows to create the click event.
3
3766
by: Morten Snedker | last post by:
If I have a number of random applications open, move the mouse cursor to a given position and do a click, the application gets the focus. That is what this simple code should illustrate: Dim pt As Point Dim wnd As IntPtr Const WM_LBUTTONUP = &H202 '//LButton up Const WM_LBUTTONDOWN = &H201 '//LButton down
5
2394
by: moonie | last post by:
I have an msn style c# windows application with a form and panel on it. A news list is drawn from the database and dynamically added via labels, link lables during form loading. In this application at run time this list should be generated again as the filtering criteria changes. So I clear the controls(labels) on the panel, get the list from the database and generate the list again. The list is created and it works fine. But sometimes...
5
30649
by: nuhfeken | last post by:
We have a C# winform that uses the MVP design pattern for the user interface. For reasons I'd rather not explain we need to simulate a right mouse click on a specific control to deactivate the control. I found code that almost does what we need. private static extern void mouse_event( UInt32 dwFlags, // motion and click options UInt32 dx, // horizontal position or change UInt32 dy, //...
3
1455
by: datla20s | last post by:
How to Open extra inofrmation box with a mouse click without changing the webpage I found an example to show what exacty I am looking for: Go to this link: http://travel.yahoo.com/;_ylc=X3oDMTE5MGRqZDdoBF9TAzI3MTYxNDkEc2VjA2ZwLXRyb3VnaARzbGsDc3Bpcml0LWZpeGVk There will be a world map in this page
0
3107
by: katiezhu | last post by:
I'm working a project. It's about screen control. I write the program using c/c++ in visual studio 2008. I just use my hand to replace mouse to control screen. The code is given below: //Must have the following line for console mode #include "stdafx.h" #include <stdlib.h> #include <stdio.h> #include <math.h> #include <conio.h> #include <cv.h>
0
8896
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9416
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9269
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9192
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8121
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4523
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4787
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3231
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.