如何在C#中阻止键盘和鼠标输入?
发布时间:2020-12-15 03:54:48 所属栏目:百科 来源:网络整理
导读:我正在寻找一些可以防止键盘和鼠标输入的代码(最好是C#). 解决方法 扩大乔希(正确)答案.这是该方法的PInvoke签名. public partial class NativeMethods { /// Return Type: BOOL-int ///fBlockIt: BOOL-int [System.Runtime.InteropServices.DllImportAttrib
我正在寻找一些可以防止键盘和鼠标输入的代码(最好是C#).
解决方法
扩大乔希(正确)答案.这是该方法的PInvoke签名.
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); } } 编辑 添加了一些代码来演示如何阻塞一段时间 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |