如何在C#中阻止键盘和鼠标输入?

前端之家收集整理的这篇文章主要介绍了如何在C#中阻止键盘和鼠标输入?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在寻找一些可以防止键盘和鼠标输入的代码(最好是C#).

解决方法

扩大乔希(正确)答案.这是该方法的PInvoke签名.
  1. public partial class NativeMethods {
  2.  
  3. /// Return Type: BOOL->int
  4. ///fBlockIt: BOOL->int
  5. [System.Runtime.InteropServices.DllImportAttribute("user32.dll",EntryPoint="BlockInput")]
  6. [return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)]
  7. public static extern bool BlockInput([System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)] bool fBlockIt) ;
  8.  
  9. }
  10.  
  11. public static void BlockInput(TimeSpan span) {
  12. try {
  13. NativeMethods.BlockInput(true);
  14. Thread.Sleep(span);
  15. } finally {
  16. NativeMethods.BlockInput(false);
  17. }
  18. }

编辑

添加了一些代码来演示如何阻塞一段时间

猜你在找的C#相关文章