3

Possible Duplicates:
how to Make the Mouse Freeze c#
How can I block keyboard and mouse input in C#?

I'm making a mouse macro program, and I already have the core mostly worked out. It would be nice, though, if I could temporarily block the user from using the mouse while the macro is playing... is this possible in C#?


EDIT

This code works perfectly for me:

    [DllImport("user32.dll")]
    private static extern bool BlockInput(bool block);

    public static void FreezeMouse()
    {
        BlockInput(true);
    }

    public static void ThawMouse()
    {
        BlockInput(false);
    }
Community
  • 1
  • 1
Entity
  • 7,972
  • 21
  • 79
  • 122
  • Why do you want to do this? Sounds pretty malicious to me. – ChaosPandion Oct 25 '10 at 16:55
  • 2
    You can display a message in big bold red letters "Stop moving the mouse!" – Remus Rusanu Oct 25 '10 at 16:55
  • @ChaosPandion: I wouldn't want them to interfere with the playing macro. I would have a keyboard shortcut to stop the macro and re-enable the mouse. – Entity Oct 25 '10 at 17:00
  • @Remus: lol! Thats one way to do it – Entity Oct 25 '10 at 17:00
  • Consider though that frozen mouse is immediately associated by user with frozen app and give a very bad user experience. Perhaps you can hide the cursor instead, while inside your application's form: http://msdn.microsoft.com/en-us/library/system.windows.forms.cursor.hide.aspx – Remus Rusanu Oct 25 '10 at 17:28
  • Well then the users couldn't see the cursor playing out the macro... – Entity Oct 25 '10 at 17:42
  • [Block input in C# (stackoverflow.com)](https://stackoverflow.com/questions/586547/how-can-i-block-keyboard-and-mouse-input-in-c) – Kevin Stricker Oct 25 '10 at 17:15

0 Answers0