1

I'm trying to hold my mousedown and up using code for a remote desktop sort of deal. I managed to do single and double click using this:

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

    private const int MOUSEEVENTF_LEFTDOWN = 0x02;
    private const int MOUSEEVENTF_LEFTUP = 0x04;
    private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
    private const int MOUSEEVENTF_RIGHTUP = 0x10;

    uint ClickX = Convert.ToUInt32(Cursor.Position.X);
    uint ClickY = Convert.ToUInt32(Cursor.Position.Y);
    mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, ClickX, ClickY, 0, 0);

and then double click is just 2 clicks. I found this MSDN on it but this looks like the only mousedown there is but this one is just to click and not hold I'm pretty sure.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Rachel Dockter
  • 946
  • 1
  • 8
  • 21
  • If you dont call MOUSEEVENTF_LEFTUP, the system will consider the button to be pressed until that event is called. – Unicorno Marley Apr 02 '16 at 05:01
  • so "mouse_event(MOUSEEVENTF_RIGHTDOWN, X, Y, 0, 0);" instead? i just tried that and my mouse froze for a second then nothing, it didnt hold it down – Rachel Dockter Apr 02 '16 at 05:02
  • 1
    I think you want to use SendInput. Check [this](http://stackoverflow.com/questions/5094398/how-to-programatically-mouse-move-click-right-click-and-keypress-etc-in-winfor) – scottjustin5000 Apr 02 '16 at 05:20

0 Answers0