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