【发布时间】:2019-07-11 22:22:12
【问题描述】:
想短时间屏蔽用户键盘输入,但是方法不行。
公共部分类 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);
有人有想法吗?已经谢谢了
【问题讨论】:
-
究竟是什么不起作用?你从
BlockInput得到的返回值是多少?如果它不为零,您可以使用GetLastError获取最后一个错误。 -
我真的没有得到返回值