public HooksThread(UsedEvents usedEvents, AWnd wMsg) { _usedEvents = usedEvents; _wMsg = wMsg; AThread.Start(_Thread, sta: false); //important: not STA, because we use lock, which dispatches sent messages if STA Api.WaitForSingleObject(_eventStartStop, -1); }
/// <summary> /// Sends key/mouse event data (copied to _keyData etc) to the main thread. /// Returns true to eat (block, discard) the event. /// On 1100 ms timeout returns false. /// </summary> bool _Send(UsedEvents eventType) { //using var p1 = APerf.Create(); _wMsg.SendNotify(Api.WM_USER + 1, _messageId, (int)eventType); bool timeout = Api.WaitForSingleObject(_eventSendData, 1100) == Api.WAIT_TIMEOUT; lock (this) { if (timeout) { timeout = Api.WaitForSingleObject(_eventSendData, 0) == Api.WAIT_TIMEOUT; //other thread may SetEvent between WaitForSingleObject and lock } _messageId++; return(_eat && !timeout); } //info: HookWin._HookProcLL will print warning if > LowLevelHooksTimeout-50. Max LowLevelHooksTimeout is 1000. }