What could be the problem? Windows 10 x64. How many did not try in any way fail to organize a program click of the mouse through these api functions. (pressing does not occur absolutely anywhere!)

static extern void mouse_event( uint dwFlags, uint dx, uint dy, uint dwData, IntPtr dwExtraInfo ); static public void MouseClick() { Point ptCoords = new Point(); GetCursorPos(ref ptCoords); uint x = (uint) ptCoords.X; uint y = (uint) ptCoords.Y; System.IntPtr ptr = new IntPtr(); mouse_event(0x0002, x, y, 0, ptr); mouse_event(0x0004, x, y, 0, ptr); } 

    1 answer 1

    Perhaps you have incorrectly written signatures for WinAPI functions or types. Ready-made signatures for almost any functions can be found here . Here is a working example:

     [StructLayout(LayoutKind.Sequential)] struct Point { public int X; public int Y; public Point(int x, int y) { X = x; Y = y; } } class Program { [DllImport("user32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] static extern bool GetCursorPos(out Point lpPoint); [DllImport("user32.dll")] static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, UIntPtr dwExtraInfo); const uint MOUSEEVENTF_LEFTDOWN = 0x0002; const uint MOUSEEVENTF_LEFTUP = 0x0004; static void Main(string[] args) { Point ptCoords; GetCursorPos(out ptCoords); uint x = (uint)ptCoords.X; uint y = (uint)ptCoords.Y; UIntPtr ptr = new UIntPtr(); mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, ptr); mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, ptr); } } 
    • The fact of the matter is that I tried a bunch of different ways of announcements and calls proposed from Google, nothing works. - thez
    • @thez, very strange. As an option, you do not have an antivirus installed? It can block software emulation of clicks. - kmv
    • Thank you for your attention, I found the reason, indeed, the data of the api was blocked by some kind of application (or rather, the game). Stackoverflow.com/questions/526980/… CLOSED! - thez