Frage

I have been trying to make a script that drags your mouse down when you left click. So far my code looks like this (just for the test I have been using the Write "1" part)

static void Main(string[] args)
{
    while (true)
    {
        while (Console.ReadKey(false).Key == ConsoleKey.LeftWindows)
            Console.Write("1");
    }
}

Now I know that LeftWindows is not the left mousebutton. I just had no idea.

War es hilfreich?

Lösung

Since I don't think you can get mouse events only from your program, you will have to hook to the global mouse events.
That means that you'll be notified about EVERY mouse event in the system.
You can hook to global mouse events like this:
Global mouse event handler

When you receive WM_LBUTTONDOWN, it means that the left button was pressed. Then you can move the mouse like this:
How to move mouse cursor using C#?

(I recommend that your handling code will be done in another thread than the one which captures to mouse events. Otherwise, you might miss events.)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top