我想在短时间内阻止用户键盘输入,但是该方法不起作用。
公共局部类NativeMethods {
[DllImport("user32.dll", EntryPoint = "BlockInput")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool BlockInput([MarshalAs(UnmanagedType.Bool)] bool fBlockIt);
}
public class KeyboardBlocker
{
public static void Block(int span)
{
try
{
NativeMethods.BlockInput(true);
Console.WriteLine("should have blocked");
Thread.Sleep(span);
}
finally
{
NativeMethods.BlockInput(false);
有人有想法吗?已经谢谢了
答案 0 :(得分:0)
显然,BlockInput函数无法在64位上工作。您可以从这里尝试答案: Using BlockInput to block keyboard and mouse input。