0
这里的一个触摸板虚拟键盘按钮。当我按下屏幕上的'TOUCH'时,将会显示'ab'。我试图使用了BlockInput防止鼠标和键盘的任何输入在2秒内按下触摸按键之后。但它不起作用,我认为需要为BlockInput设置一个定时器,any1知道该怎么做?这里是我的代码:使用了BlockInput到方框键盘和鼠标输入
public partial class TRY
{
[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 void TOUCH(string key)
{
if (key == "Press")
{
PressAndRelease("a");
PressAndRelease("b");
ReleaseKeys();
TRY.BlockInput(true);
Thread.Sleep(2000);
TRY.BlockInput(false);
}
}
你是不是检查错误,你忽略了BlockInput()的返回值。所以确定,你不知道为什么它不起作用。当它返回false时抛出一个Win32Exception。 – 2012-04-04 05:09:00
@HansPassant:THX乌拉圭回合信息。当我尝试编译它时,我的代码没有错误。但是在'Thread.Sleep(2000)'的时候,仍然可以接收用户的输入。你能告诉我解决问题的方法吗? – hakunabean 2012-04-04 06:32:15
避免在此(UI?)线程中使用睡眠并使用后台工作程序。 – 2012-04-04 11:27:26