0
所以我用SetWindowsHookEx()
做了一個全局熱鍵。我想要它做的是當我按下鼠標右鍵時,它應該一次又一次地執行一些代碼。問題是,如果我按下鼠標右鍵,它只會執行一次。SetWindowsHookEx,在按下鼠標按鈕時執行代碼
這是我的回調函數:
private static IntPtr ButtonHookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode >= 0)
{
if (wParam == (IntPtr)WM_RBUTTONDOWN)
{
_m.rtbLog.AppendText("Right mouse button was clicked \n");
}
else if (wParam == (IntPtr)WM_LBUTTONDOWN)
{
_m.rtbLog.AppendText("Left mouse button was clicked \n");
}
}
return CallNextHookEx(MainWindow._hookId, nCode, wParam, lParam);
}
重複運行代碼需要一個循環或一個Timer。當然,計時器就是你正在尋找的東西,因爲當一個循環需要被人的手指啓動和停止時,循環多久可以循環。在mousedown上啓動定時器,在mouseup通知中停止它。計時器通常精確到〜16毫秒。 –