如何阻止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);
}
}
编辑
添加了一些代码来说明如何阻止一个时间间隔
你可以给出更多的背景知道为什么你想这样做吗? – JaredPar 2009-02-25 15:47:01
您的意思是只在您的应用程序中或整个系统中的全局? – 2009-02-25 15:48:27
什么;毕竟,你可能指的是一个文本框,它设置只读属性会做到这一点。 – 2009-02-25 15:48:37