void _Thread() { _tid = AThread.NativeId; AHookWin hookK = null, hookM = null; if (_usedEvents.Has(UsedEvents.Keyboard)) { hookK = AHookWin.Keyboard(_KeyboardHookProc); //note: don't use lambda, because then very slow JIT on first hook event } if (_usedEvents.Has(UsedEvents.Mouse)) { hookM = AHookWin.MouseRaw_(_MouseHookProc); } if (_usedEvents.Has(UsedEvents.MouseEdgeMove)) { _emDetector = new MouseTriggers.EdgeMoveDetector_(); } //tested: don't need JIT-compiling. Api.SetEvent(_eventStartStop); while (Api.GetMessage(out var m) > 0) { Api.DispatchMessage(m); } //AOutput.Write("hooks thread ended"); hookK?.Dispose(); hookM?.Dispose(); _emDetector = null; Api.SetEvent(_eventStartStop); }
void _SetTempKeybHook() { //AOutput.Write(". hook"); if (_keyHook == null) { _keyHook = AHookWin.Keyboard(k => { if (ATime.WinMilliseconds >= _keyHookTimeout) { _ResetUpAndUnhookTempKeybHook(); ADebug.Print("hook timeout"); } else { var mod = k.Mod; if (0 != (mod & _upMod) && k.IsUp) { _upMod &= ~mod; if (_upMod == 0 && _upEvent == 0 && _upTrigger != null) { _triggers.RunAction_(_upTrigger, _upArgs); _ResetUp(); } } if (0 != (mod & _eatMod)) { //AOutput.Write(k); k.BlockEvent(); if (k.IsUp) { _eatMod &= ~mod; } } if (0 == (_upMod | _eatMod)) { _UnhookTempKeybHook(); } } }, setNow: false); } if (!_keyHook.IsSet) { _keyHook.Hook(); } _keyHookTimeout = _keyHook.IgnoreModInOtherHooks_(5000); }