473,405 Members | 2,294 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 22017
Just call the method.

Cor

<el***********@gmail.comschreef in bericht
news:11**********************@f1g2000cwa.googlegro ups.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.comschreef in bericht
news:11**********************@f1g2000cwa.googlegro ups.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...@gmail.com wrote:
I don't understand. Call which method?

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

Cor

<el***********@gmail.comschreef in bericht
news:11**********************@f1g2000cwa.googlegro ups.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(null,null)
<el***********@gmail.comschreef in bericht
news:11**********************@80g2000cwy.googlegro ups.com...
>I don't understand. Call which method?

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

Cor

<el***********@gmail.comschreef in bericht
news:11**********************@f1g2000cwa.googlegr oups.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.googlegr oups.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.googlegr oups.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***********@gmail.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***********@gmail.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***********@gmail.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 "experimenter'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
But all applications respond to keyboard presses and mouse clicks. I
just want to pretend I'm the mouse. I want to control ALL
applications... how would a mouse/keyboard do it? Can't I just send raw
input?

Lucian Wischik wrote:
el***********@gmail.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 "experimenter'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 #11
el***********@gmail.com wrote:
>But all applications respond to keyboard presses and mouse clicks. I
just want to pretend I'm the mouse. I want to control ALL
applications... how would a mouse/keyboard do it? Can't I just send raw
input?
Pretending to be the mouse/keyboard is much easier. The win32 function
to send raw input is "SendInput" and there's a .net wrapper around it
whose name I've forgotten.

--
Lucian
Dec 11 '06 #12
Thanks for your help so far. This is the most frustrating thing ever. I
switched to using mouse_event, which should be exactly like SendInput.
(Is that the wrapper?)

Anyways, I am receiving the WM_LBUTTONDOWN and WM_LBUTTONDOWN as seen
on Spy++. However, nothing is getting clicked

Here is my code to click:

short x = BitConverter.ToInt16(m_pBuff, 0);
short y = BitConverter.ToInt16(m_pBuff, 2);

Winapi.POINT p = new Winapi.POINT(x, y);
Winapi.ClientToScreen(m_target, ref p);
System.Diagnostics.Debug.WriteLine(p.X.ToString() + "," +
p.Y.ToString());
Winapi.mouse_event((uint)Winapi.MouseEventTFlags.A BSOLUTE |
(uint)Winapi.MouseEventTFlags.LEFTDOWN, (uint)p.X, (uint)p.Y, 0,
System.UIntPtr.Zero);
Winapi.mouse_event((uint)Winapi.MouseEventTFlags.A BSOLUTE |
(uint)Winapi.MouseEventTFlags.LEFTUP, (uint)p.X, (uint)p.Y, 0,
System.UIntPtr.Zero);
Here is my code from the "mirrored" application, in the WndProc which
is sending the click. It's basically an image replica of the real
application:

case (int)Winapi.WM_LBUTTONUP:
byte[] b = BitConverter.GetBytes((int)m.LParam);
System.Diagnostics.Debug.WriteLine(b.Length);
m_networkstream.Write(b, 0, b.Length);
break;
Lucian Wischik wrote:
el***********@gmail.com wrote:
But all applications respond to keyboard presses and mouse clicks. I
just want to pretend I'm the mouse. I want to control ALL
applications... how would a mouse/keyboard do it? Can't I just send raw
input?

Pretending to be the mouse/keyboard is much easier. The win32 function
to send raw input is "SendInput" and there's a .net wrapper around it
whose name I've forgotten.

--
Lucian
Dec 12 '06 #13
I have a hypothesis -- could it be that mouse_event coordinates are
different from actual pixel coordinates? The MSDN doc says 0,0 is the
upper left and 65535,65535 is the bottom right. That's weird. What if
my resolution is 1280,1024? Do I need to multiple the screen
coordinates I get by 65 or something?
el***********@gmail.com wrote:
Thanks for your help so far. This is the most frustrating thing ever. I
switched to using mouse_event, which should be exactly like SendInput.
(Is that the wrapper?)

Anyways, I am receiving the WM_LBUTTONDOWN and WM_LBUTTONDOWN as seen
on Spy++. However, nothing is getting clicked

Here is my code to click:

short x = BitConverter.ToInt16(m_pBuff, 0);
short y = BitConverter.ToInt16(m_pBuff, 2);

Winapi.POINT p = new Winapi.POINT(x, y);
Winapi.ClientToScreen(m_target, ref p);
System.Diagnostics.Debug.WriteLine(p.X.ToString() + "," +
p.Y.ToString());
Winapi.mouse_event((uint)Winapi.MouseEventTFlags.A BSOLUTE |
(uint)Winapi.MouseEventTFlags.LEFTDOWN, (uint)p.X, (uint)p.Y, 0,
System.UIntPtr.Zero);
Winapi.mouse_event((uint)Winapi.MouseEventTFlags.A BSOLUTE |
(uint)Winapi.MouseEventTFlags.LEFTUP, (uint)p.X, (uint)p.Y, 0,
System.UIntPtr.Zero);
Here is my code from the "mirrored" application, in the WndProc which
is sending the click. It's basically an image replica of the real
application:

case (int)Winapi.WM_LBUTTONUP:
byte[] b = BitConverter.GetBytes((int)m.LParam);
System.Diagnostics.Debug.WriteLine(b.Length);
m_networkstream.Write(b, 0, b.Length);
break;
Lucian Wischik wrote:
el***********@gmail.com wrote:
>But all applications respond to keyboard presses and mouse clicks. I
>just want to pretend I'm the mouse. I want to control ALL
>applications... how would a mouse/keyboard do it? Can't I just send raw
>input?
Pretending to be the mouse/keyboard is much easier. The win32 function
to send raw input is "SendInput" and there's a .net wrapper around it
whose name I've forgotten.

--
Lucian
Dec 12 '06 #14
<el***********@gmail.comwrote in message
news:11*********************@f1g2000cwa.googlegrou ps.com...
>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?
Move the mouse to that position using Cursor.Position or place a form there.
You can;t draw to that location so have to place something there.

Michael
Dec 12 '06 #15
el***********@gmail.com wrote:
>Thanks for your help so far. This is the most frustrating thing ever. I
switched to using mouse_event, which should be exactly like SendInput.
(Is that the wrapper?)
Doh! Read the MSDN docs of functions that are mentioned to you but you
don't yet know! mouse_event is deprecated in favour of SendInput.

>Anyways, I am receiving the WM_LBUTTONDOWN and WM_LBUTTONDOWN as seen
on Spy++. However, nothing is getting clicked
The following (complete) program works, in that I programmatically
synthesize a click on the button and the button's OnClick event does
indeed get called. You might use this as a starting point for your
further explorations.

Like you, I created a button within my own C# application and spoofed
a click on that. What you will probably find is that (1) C# and .net
applications might respond different to mouse events from other
applications, and (2) response by a button INSIDE your own process
will be different from response by a button OUTSIDE. The reason for my
conjecture (1) is that I wouldn't expect the .net authors to follow
the win32 mouse model slavishly. The reason for my conjecture number
(2) is that an external process will have its own asynchronous
message-loop.

Things that I discovered: I couldn't send both MOUSEEVENTF_LBUTTONDOWN
and MOUSEEVENTF_LBUTTONUP both within a single call to SendInput. What
I did in this code was to space them out with a timer. My reasons for
doing this is my experience that lots of people write code which
depends on the message-queue being cleared after the first event
before later stuff happens. (I coded my MOUSEINPUT structure to allow
up to two events. But, following this discovery, my code only uses the
first event.)

I also discovered about how my .net button responded to mouse events.
When it received the MOUSEEVENTF_LBUTTONDOWN, it seemed to ignore the
mouse coordinate parameters of the MOUSEINPUT structure. Instead it
queried the cursor position. I suspect that regular win32 controls
will behave differently here.

Note: I put my code in response to a timer. Partly because I
anticipated problems like the first one I discovered. Partly because
of my conjecture (2): I thought that if I put my code in response to a
mouseclick of mine, then it would end up in a confused state when it
gets another mouseclick immediately.

I've spent five long paragraphs explaining these things. That's
because, as I said, controlling applications through synthesized
mouse-clicks requires a lot of experience with how windows deals with
mice and messages, and a lot of experiments. It also means that no one
will be able to help you "in abstract". They'll only be able to help
when you give very concrete details of the application you're trying
to control, and maybe not even then.

Note: it's because of all these irritations that I suggested using
SendMessage(WM_COMMAND) instead. That reliably bypasses all the
irritations. It works great for sending many kinds of notifications of
button-clicks or slideybar-drags and so on.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication4
{

public partial class Form1:Form
{
[System.Runtime.InteropServices.StructLayout(System .Runtime.InteropServices.LayoutKind.Sequential)]
public struct MOUSEINPUT
{ public static MOUSEINPUT Zero()
{ MOUSEINPUT mi;

mi.type1=INPUT_MOUSE;mi.dx1=0;mi.dy1=0;mi.mouseDat a1=0;mi.dwFlags1=0;mi.time1=0;mi.dwExtraInfo1=IntP tr.Zero;

mi.type2=INPUT_MOUSE;mi.dx2=0;mi.dy2=0;mi.mouseDat a2=0;mi.dwFlags2=0;mi.time2=0;mi.dwExtraInfo2=IntP tr.Zero;
return mi;
}
public int Size() {return (int)Count()*28;}
public UInt32 Count() {if (dwFlags2!=0) return 2; else if
(dwFlags1!=0) return 1; else return 0;}
public Int32 type1, dx1,dy1, mouseData1, dwFlags1, time1; public
IntPtr dwExtraInfo1;
public Int32 type2, dx2,dy2, mouseData2, dwFlags2, time2; public
IntPtr dwExtraInfo2;
}
const Int32 INPUT_MOUSE=0;
const Int32 MOUSEEVENTF_LEFTDOWN=0x0002;
const Int32 MOUSEEVENTF_LEFTUP = 0x0004;
const Int32 MOUSEEVENTF_ABSOLUTE = 0x8000;
[System.Runtime.InteropServices.DllImport("user32.d ll")]
public static extern UInt32 SendInput(UInt32 nInputs, ref MOUSEINPUT
pInputs, Int32 cbSize);
public Form1()
{ InitializeComponent();
}

private void button2_Click(object sender,EventArgs e)
{ MessageBox.Show("click2");
}

int state=1;

private void button1_Click(object sender,EventArgs e)
{ state=1;
}

private void timer1_Tick(object sender,EventArgs e)
{ if (state==0) return;
MOUSEINPUT mi = MOUSEINPUT.Zero();
if (state==1)
{ Point pt=new Point(button2.Width/2,button2.Height/2),
oldpos=Cursor.Position;
Cursor.Position = button2.PointToScreen(pt);
mi.dwFlags1=MOUSEEVENTF_LEFTDOWN;
uint r=SendInput(mi.Count(), ref mi, mi.Size());
if (r==mi.Count()) Console.Beep();
state=3; return;
}
if (state==3)
{ mi.dx1=0; mi.dy1=0; mi.dwFlags1=MOUSEEVENTF_LEFTUP; uint
r=SendInput(1,ref mi, mi.Size());
if (r==1) Console.Beep();
state=0; return;
}
}

}
}
--
Lucian
Dec 12 '06 #16
AHHhhhh... this helps a lot. By picking apart your example, I found out
that the Cursor needs to be above the button for the click to work. The
reason I didn't think this was needed at first was because I was able
to do the fake click thing correctly in WinAPI and minesweeper. I
didn't know buttons were different. Works great now.... I guess
Lucian Wischik wrote:
el***********@gmail.com wrote:
Thanks for your help so far. This is the most frustrating thing ever. I
switched to using mouse_event, which should be exactly like SendInput.
(Is that the wrapper?)

Doh! Read the MSDN docs of functions that are mentioned to you but you
don't yet know! mouse_event is deprecated in favour of SendInput.

Anyways, I am receiving the WM_LBUTTONDOWN and WM_LBUTTONDOWN as seen
on Spy++. However, nothing is getting clicked

The following (complete) program works, in that I programmatically
synthesize a click on the button and the button's OnClick event does
indeed get called. You might use this as a starting point for your
further explorations.

Like you, I created a button within my own C# application and spoofed
a click on that. What you will probably find is that (1) C# and .net
applications might respond different to mouse events from other
applications, and (2) response by a button INSIDE your own process
will be different from response by a button OUTSIDE. The reason for my
conjecture (1) is that I wouldn't expect the .net authors to follow
the win32 mouse model slavishly. The reason for my conjecture number
(2) is that an external process will have its own asynchronous
message-loop.

Things that I discovered: I couldn't send both MOUSEEVENTF_LBUTTONDOWN
and MOUSEEVENTF_LBUTTONUP both within a single call to SendInput. What
I did in this code was to space them out with a timer. My reasons for
doing this is my experience that lots of people write code which
depends on the message-queue being cleared after the first event
before later stuff happens. (I coded my MOUSEINPUT structure to allow
up to two events. But, following this discovery, my code only uses the
first event.)

I also discovered about how my .net button responded to mouse events.
When it received the MOUSEEVENTF_LBUTTONDOWN, it seemed to ignore the
mouse coordinate parameters of the MOUSEINPUT structure. Instead it
queried the cursor position. I suspect that regular win32 controls
will behave differently here.

Note: I put my code in response to a timer. Partly because I
anticipated problems like the first one I discovered. Partly because
of my conjecture (2): I thought that if I put my code in response to a
mouseclick of mine, then it would end up in a confused state when it
gets another mouseclick immediately.

I've spent five long paragraphs explaining these things. That's
because, as I said, controlling applications through synthesized
mouse-clicks requires a lot of experience with how windows deals with
mice and messages, and a lot of experiments. It also means that no one
will be able to help you "in abstract". They'll only be able to help
when you give very concrete details of the application you're trying
to control, and maybe not even then.

Note: it's because of all these irritations that I suggested using
SendMessage(WM_COMMAND) instead. That reliably bypasses all the
irritations. It works great for sending many kinds of notifications of
button-clicks or slideybar-drags and so on.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication4
{

public partial class Form1:Form
{
[System.Runtime.InteropServices.StructLayout(System .Runtime.InteropServices.LayoutKind.Sequential)]
public struct MOUSEINPUT
{ public static MOUSEINPUT Zero()
{ MOUSEINPUT mi;

mi.type1=INPUT_MOUSE;mi.dx1=0;mi.dy1=0;mi.mouseDat a1=0;mi.dwFlags1=0;mi.time1=0;mi.dwExtraInfo1=IntP tr.Zero;

mi.type2=INPUT_MOUSE;mi.dx2=0;mi.dy2=0;mi.mouseDat a2=0;mi.dwFlags2=0;mi.time2=0;mi.dwExtraInfo2=IntP tr.Zero;
return mi;
}
public int Size() {return (int)Count()*28;}
public UInt32 Count() {if (dwFlags2!=0) return 2; else if
(dwFlags1!=0) return 1; else return 0;}
public Int32 type1, dx1,dy1, mouseData1, dwFlags1, time1; public
IntPtr dwExtraInfo1;
public Int32 type2, dx2,dy2, mouseData2, dwFlags2, time2; public
IntPtr dwExtraInfo2;
}
const Int32 INPUT_MOUSE=0;
const Int32 MOUSEEVENTF_LEFTDOWN=0x0002;
const Int32 MOUSEEVENTF_LEFTUP = 0x0004;
const Int32 MOUSEEVENTF_ABSOLUTE = 0x8000;
[System.Runtime.InteropServices.DllImport("user32.d ll")]
public static extern UInt32 SendInput(UInt32 nInputs, ref MOUSEINPUT
pInputs, Int32 cbSize);
public Form1()
{ InitializeComponent();
}

private void button2_Click(object sender,EventArgs e)
{ MessageBox.Show("click2");
}

int state=1;

private void button1_Click(object sender,EventArgs e)
{ state=1;
}

private void timer1_Tick(object sender,EventArgs e)
{ if (state==0) return;
MOUSEINPUT mi = MOUSEINPUT.Zero();
if (state==1)
{ Point pt=new Point(button2.Width/2,button2.Height/2),
oldpos=Cursor.Position;
Cursor.Position = button2.PointToScreen(pt);
mi.dwFlags1=MOUSEEVENTF_LEFTDOWN;
uint r=SendInput(mi.Count(), ref mi, mi.Size());
if (r==mi.Count()) Console.Beep();
state=3; return;
}
if (state==3)
{ mi.dx1=0; mi.dy1=0; mi.dwFlags1=MOUSEEVENTF_LEFTUP; uint
r=SendInput(1,ref mi, mi.Size());
if (r==1) Console.Beep();
state=0; return;
}
}

}
}
--
Lucian
Dec 12 '06 #17
Setting the cursor position is a really good idea. It definitely helped
me debug this problem. Thanks!

Michael C wrote:
<el***********@gmail.comwrote in message
news:11*********************@f1g2000cwa.googlegrou ps.com...
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?

Move the mouse to that position using Cursor.Position or place a form there.
You can;t draw to that location so have to place something there.

Michael
Dec 12 '06 #18
<el***********@gmail.comwrote in message
news:11**********************@j72g2000cwa.googlegr oups.com...
AHHhhhh... this helps a lot. By picking apart your example, I found out
that the Cursor needs to be above the button for the click to work. The
reason I didn't think this was needed at first was because I was able
to do the fake click thing correctly in WinAPI and minesweeper. I
didn't know buttons were different. Works great now.... I guess
Maybe there is an issue with capturing the mouse. When a button gets a mouse
down message it will generally call SetCapture. This way if the user moves
the mouse off the button (with the mouse down) it will get a message this
has happened. If the user does this and then loses the capture without
letting go of the mouse (eg pushing ctrl-esc to show the start menu) then
the button will know it's been released. Maybe SetCapture fails if the mouse
is not over the button.

Michael
Dec 12 '06 #19

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

Similar topics

3
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...
3
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...
3
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...
4
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...
3
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...
5
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...
5
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...
3
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: ...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.