Using SendInput to emulate *double* click

  • Thread starter Thread starter Richard A. Lowe
  • Start date Start date
R

Richard A. Lowe

I'm using P/Invoke to call SendInput (using code culled
from these newsgroups!) to send mouse events to a window.
But I'm unsure how to send double-clicks. A VB6 article I
saw on SendInput suggested simply queueing two click
events, but this is not working for me, regardless of the
delay I put between clicks. So give this as a click
(where INPUT is an appropriate structure for sending the
SendInput data):

public static void Click()
{
INPUT aInput = new INPUT();

aInput.type = INPUT_MOUSE;
aInput.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
aInput.mi.dwExtraInfo = 0;
aInput.mi.mouseData = 0;
aInput.mi.time = 0;

int aResult = SendInput(1, ref aInput, 28 );

INPUT bInput = new INPUT();

bInput.type = INPUT_MOUSE;
bInput.mi.dwFlags = MOUSEEVENTF_LEFTUP;
bInput.mi.dwExtraInfo = 0;
bInput.mi.mouseData = 0;
bInput.mi.time = 0;

int bResult = SendInput(1, ref bInput, 28 );
}

The call:

Click();
Thread.Sleep(50);
Click();

Does not work no double-click is produced no matter if the
delay is 0, 50, 100 etc. How can I send a double-click?

TIA
Richard
 
I want to control a 'legacy' GUI that you must dbl-click
on in certain forms. This GUI will run on an undisturbed
server and has tolerance for failure. But it needs the
double-click event at certain points.

Richard
 
Are you sure the structure is right? Can you post a copy of your
definition of the structure?

Jonathan Schafer
 
Thanks Jonathan, I've pasted it below, however keep in
mind that other SendInput calls work as expected, both
single clicks AND mouse movements. My original assumption
was that double-clicks were a different type of input, but
then I saw the example where a double-click is created via
sending two clicks in rapid succession.

[StructLayout(LayoutKind.Explicit)]
public struct MOUSEINPUT
{
[FieldOffset(0)] public int dx; //
4
[FieldOffset(4)] public int dy; //
4
[FieldOffset(8)] public int mouseData; // 4
[FieldOffset(12)] public int dwFlags; //
4
[FieldOffset(16)] public int time; //
4
[FieldOffset(20)] public int dwExtraInfo; //
4
};
 
I searched through Google regarding SendInput and double-click. Every
post mentioned doing it the same way you were. I read in a couple of
posts that timing was an issue. This may be what you are
experiencing.

Jonathan Schafer
 
Back
Top