none
C# - Disable mouse and keyboard on windows 8 RRS feed

  • Question

  • Hello,

    I'm trying to create a program in C# that disable mouse and keyboard on my Windows 8 VM (I don't want to kill my own computer).

    I found some content on Internet that proposed to use register and use this to disable keyboard :

    To disable: Add a new REG_BINARY value called "Scancode Map" to "HKEY_LOCAL_ MACHINE\System\CurrentControlSet\Control\Keyboard Layout" with a data value of "00000000000000000300000000005BE000005CE000000000". Unfortunetly it doesn't work :/

    Does someone have any idea ? Thank you so much for helping me :)

    Saturday, August 25, 2018 12:42 AM

All replies

  • Hello,

    I'm trying to create a program in C# that disable mouse and keyboard on my Windows 8 VM (I don't want to kill my own computer).

    I found some content on Internet that proposed to use register and use this to disable keyboard :

    To disable: Add a new REG_BINARY value called "Scancode Map" to "HKEY_LOCAL_ MACHINE\System\CurrentControlSet\Control\Keyboard Layout" with a data value of "00000000000000000300000000005BE000005CE000000000". Unfortunetly it doesn't work :/

    Does someone have any idea ? Thank you so much for helping me :)

    Saturday, August 25, 2018 12:41 AM
  • You can use BlockInput

    or

    Low Level Hooks (WH_KEYBOARD_LL, WH_MOUSE_LL

    Saturday, August 25, 2018 7:09 AM
  • Hi ClaraJ,

    >>C# - Disable mouse and keyboard on windows 8

    There is a BlockInput win32 api that do this job: BlockInput function.

    From MSDN, you can use this function to block keyboard and mouse input events from reaching applications. 

    Here's the PInvoke signature for that method:

    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);
      }
    }

    Refer: How can I block keyboard and mouse input in C#?

    Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Saturday, August 25, 2018 7:55 AM