views:

189

answers:

2

Hi,
I am writing a small program which can simulate mouse clicks at specified positions. Using the Win32 API call mouse_event like so:

[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, UIntPtr dwExtraInfo);

[Flags]
public enum MouseEventFlags : uint
{
    LEFTDOWN = 0x00000002,
    LEFTUP = 0x00000004,
    MIDDLEDOWN = 0x00000020,
    MIDDLEUP = 0x00000040,
    MOVE = 0x00000001,
    ABSOLUTE = 0x00008000,
    RIGHTDOWN = 0x00000008,
    RIGHTUP = 0x00000010
}

mouse_event((uint)(MouseEventFlags.LEFTDOWN | MouseEventFlags.LEFTUP), x, y, 0, UIntPtr.Zero);

Works perfectly fine, except when the mouse cursor is over a Flash application. Flash seems to ignore the simulated mouse click. What could be the reason for this? And how do I fix it?

Thank you!

A: 

Try

mouse_event((uint)
(MouseEventFlags.LEFTDOWN | MouseEventFlags.LEFTUP | MouseEventFlags.ABSOLUTE), 
 x, y, 0, UIntPtr.Zero);

Also, for some strange reason I've had problems with the above P/Invoke calling convention, see http://stackoverflow.com/questions/1740045/simulating-a-mouse-button-click-in-windows/3002585#3002585

ohadsc
A: 

the last post did not work.

faewfaw