Just how to lock the keyboard and mouse? Already viewed this page http://www.cyberforum.ru/csharp-beginners/thread595784.html

but this code does not work when starting the application.

    1 answer 1

    Solution 1:

    You can turn off the power to the device. I gave the answer how to do it here:

    Enable / Disable USB Ports or Devices

    Solution 2:

    You can intercept through the WIN API to cancel any signal from the desired device.

    Solution 3:

    It is possible through the WIN API to block the input itself:

    public partial class NativeMethods { /// Return Type: BOOL->int ///fBlockIt: BOOL->int [System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint="BlockInput")] [return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)] public static extern bool BlockInput([System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)] bool fBlockIt) ; } public static void BlockInput(TimeSpan span) { try { NativeMethods.BlockInput(true); Thread.Sleep(span); } finally { NativeMethods.BlockInput(false); } } 

    As can be seen from the method, it simply blocks the input from the mouse and keyboard for some time set via TimeSpan. I think it will not be difficult to figure it out.

    The answer is found here: https://stackoverflow.com/questions/586547/how-can-i-block-keyboard-and-mouse-input-in-c

    last found for "api block mouse input c #"

    • Yyyy, what a cool idea for an April Fool's joke! Like definitely! )) If a colleague gape - he needs to turn off the mouse for an hour, let him just remember the keyboard shortcuts. )) - AK
    • Thank! Solution 3 works, but only when the application is started as an administrator. - MacAntony 4:21
    • one
      Most likely the second part you shove not inside some class. Or you push all solution already in any existing class. In short, I checked the code works. I do not know what mistakes you climb :) But the solution is 100% working. - Andrew
    • @AK is better to quietly replace the semicolon in his project with the same visually, but with a different ASCII code ... It seems GeekQuote is called or something ... Karoch everywhere there will be errors that there is no semicolon, even if they are visually there .... Bring a person to white hot one: D - Andrew
    • And you can just block the introduction of ";". That is, leave all the buttons working, but the hook to cancel the introduction of this character .... Here is a man fucking if the key works on other layouts, but a specific character is not entered .... - Andrew