我怎样才能阻止C#键盘和鼠标输入? [英] How can I block keyboard and mouse input in C#?
本文介绍了我怎样才能阻止C#键盘和鼠标输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在找一些code(preferably C#),将prevent键盘和鼠标输入。
I'm looking for some code (preferably C#) that will prevent keyboard and mouse input.
推荐答案
扩展在约什的(正确的)答案。下面是该方法的签名的PInvoke。
Expanding on Josh's (correct) answer. Here's the PInvoke signature for that method.
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);
}
}
修改
增加了一些code来演示如何阻止间隔
Added some code to demonstrate how to block for an interval
这篇关于我怎样才能阻止C#键盘和鼠标输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文