为什么BlockInput对我不起作用?我忘了什么吗?

问题描述 投票:-1回答:1

我想在短时间内阻止用户键盘输入,但该方法不起作用。

public partial class 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);

有人有想法吗?谢谢

c# .net dll user32
1个回答
0
投票

显然,BlockInput函数不能在64位中工作。你可以试试这里的答案:Using BlockInput to block keyboard and mouse input

© www.soinside.com 2019 - 2024. All rights reserved.