禁用键盘/鼠标在C#鼠标、键盘

2023-09-03 01:49:00 作者:何必强颜欢笑

我需要禁用键盘/鼠标或都为特定的时间段,在系统级我的应用程序。

I need to disable keyboard/mouse or both for specific time period at system level in my application.

我有以下做

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

    }

C语言对这个任务$ C $是完整的,但是当CTRL + ALT + DELETE键盘和鼠标的用户点击的再次合作。 任何机构可以告诉我如何停止?

By this code the task is complete but when user click on CTRL+ALT+DELETE keyboard and mouse are working again. Can any body tell me how to stop this?

推荐答案

Windows级保护快捷键和宏( CTRL + ALT + 删除 WINDOWS + →, ALT + TAB , CTRL + SHIFT < /骨节病> + ESC )是不处理您的应用程序的消息,它们是由Windows运行时处理。您可以通过创建一个简单的形式和覆盖的WndProc 方法,并检查这些消息进行确认。反正这里是如何挂钩的一些教程keyboard:http://www.$c$cproject.com/Articles/19004/A-Simple-C-Global-Low-Level-Keyboard-Hookhttp://www.$c$cproject.com/Articles/7294/Processing-Global-Mouse-and-Keyboard-Hooks-in-Chttp://blogs.msdn.com/b/toub/archive/2006/05/03/589423.aspx

Windows level shortcuts and macros (CTRL+ALT+DEL, WINDOWS+L, ALT+TAB, CTRL+SHIFT+ ESC) are messages that are not processed by your application, they're processed by windows runtime. You can check this by creating a simple form and overriding the WndProc method and checking those messages. Anyway here are some tutorials on how to hook the keyboard:http://www.codeproject.com/Articles/19004/A-Simple-C-Global-Low-Level-Keyboard-Hookhttp://www.codeproject.com/Articles/7294/Processing-Global-Mouse-and-Keyboard-Hooks-in-Chttp://blogs.msdn.com/b/toub/archive/2006/05/03/589423.aspx