禁用键盘/鼠标在C# [英] Disable Keyboard/Mouse in c#

查看:640
本文介绍了禁用键盘/鼠标在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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-Hook
  • http://www.$c$cproject.com/Articles/7294/Processing-Global-Mouse-and-Keyboard-Hooks-in-C
  • http://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-Hook
    • http://www.codeproject.com/Articles/7294/Processing-Global-Mouse-and-Keyboard-Hooks-in-C
    • http://blogs.msdn.com/b/toub/archive/2006/05/03/589423.aspx
    • 这篇关于禁用键盘/鼠标在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆