Пример #1
0
        void _KeyHookProc(HookData.Keyboard x)
        {
            if (_DontBlock(x.IsInjected, x.dwExtraInfo, x.vkCode))
            {
                //print.it("ok", x.vkCode, !x.IsUp);
                return;
            }
            //print.it(message, x.vkCode);

            //if(x.vkCode == KKey.Delete && !x.IsUp) {
            //	//Could detect Ctrl+Alt+Del here. But SetWinEventHook(SYSTEM_DESKTOPSWITCH) is better.
            //}

            if (ResendBlockedKeys && Environment.TickCount64 - _startTime < c_maxResendTime)
            {
                //If Shift is set to turn off CapsLock, on Shift the hook receives LShift down and CapsLock down/up with no 'injected' flag, even if the Shift was pressed by a script.
                //If we resend them, the hook catches the resent keys, and the resent LShift creates an infinite loop (actually for 10 s, see c_maxResendTime).
                //Workaround: don't resend these keys if isCapsLock and the system setting is active.
                //Also SendBlocked_ prevents such infinite loop in any case.
                bool no = false;
                if (x.vkCode == KKey.CapsLock || (x.vkCode == KKey.LShift && !x.IsUp))
                {
                    no = keys.isCapsLock && keys.IsCapsLockShiftOff_();
                }

                if (!no)
                {
                    _blockedKeys ??= new keys(opt.init.key);
                    //print.it("blocked", x.vkCode, !x.IsUp, x.IsInjected);
                    _blockedKeys.AddRaw_(x.vkCode, (ushort)x.scanCode, x.SendInputFlags_);
                }
            }
            x.BlockEvent();
        }
Пример #2
0
 unsafe void _KeyboardHookProc(HookData.Keyboard k)
 {
     _keyData = *k.NativeStructPtr_;
     if (_Send(UsedEvents.Keyboard))
     {
         k.BlockEvent();
     }
 }
Пример #3
0
        void _KeyHookProc(HookData.Keyboard x)
        {
            if (_DontBlock(x.IsInjected, x.dwExtraInfo, x.vkCode))
            {
                //AOutput.Write("ok", x.vkCode, !x.IsUp);
                return;
            }
            //AOutput.Write(message, x.vkCode);

            //if(x.vkCode == KKey.Delete && !x.IsUp) {
            //	//Could detect Ctrl+Alt+Del here. But SetWinEventHook(SYSTEM_DESKTOPSWITCH) is better.
            //}

            if (ResendBlockedKeys && ATime.WinMilliseconds - _startTime < c_maxResendTime)
            {
                _blockedKeys ??= new AKeys(AOpt.Static.Key);
                //AOutput.Write("blocked", x.vkCode, !x.IsUp);
                _blockedKeys.AddRaw_(x.vkCode, (ushort)x.scanCode, x.SendInputFlags_);
            }
            x.BlockEvent();
        }
Пример #4
0
        internal bool HookProc(HookData.Keyboard k, TriggerHookContext thc)
        {
            //AOutput.Write(k.vkCode, !k.IsUp);
            Debug.Assert(!k.IsInjectedByAu);             //server must ignore

            KKey key = k.vkCode;
            KMod mod = thc.Mod;
            bool up  = k.IsUp;

            if (!up)
            {
                _UpClear();
            }

            if (thc.ModThis != 0)
            {
                if (_upTrigger != null && mod == 0 && _upKey == 0)
                {
                    _UpTriggered(thc);
                }
            }
            else if (up)
            {
                if (key == _upKey)
                {
                    _upKey = 0;
                    if (_upTrigger != null && mod == 0)
                    {
                        _UpTriggered(thc);
                    }
                }
                if (key == _eatUp)
                {
                    _eatUp = 0;
                    return(true);
                    //To be safer, could return false if AKeys.IsPressed(_eatUp), but then can interfere with the trigger action.
                }
                //CONSIDER: _upTimeout.
            }
            else
            {
                //if(key == _eatUp) _eatUp = 0;
                _eatUp = 0;

                if (_d.TryGetValue((int)key, out var v))
                {
                    HotkeyTriggerArgs args = null;
                    for (; v != null; v = v.next)
                    {
                        var x = v as HotkeyTrigger;
                        if ((mod & x.modMask) != x.modMasked)
                        {
                            continue;
                        }

                        switch (x.flags & (TKFlags.LeftMod | TKFlags.RightMod))
                        {
                        case TKFlags.LeftMod: if (thc.ModL != mod)
                            {
                                continue;
                            }
                            break;

                        case TKFlags.RightMod: if (thc.ModR != mod)
                            {
                                continue;
                            }
                            break;
                        }

                        if (v.DisabledThisOrAll)
                        {
                            continue;
                        }

                        if (args == null)
                        {
                            thc.args = args = new HotkeyTriggerArgs(x, thc.Window, key, mod);                                      //may need for scope callbacks too
                        }
                        else
                        {
                            args.Trigger = x;
                        }

                        if (!x.MatchScopeWindowAndFunc(thc))
                        {
                            continue;
                        }

                        if (x.action != null)
                        {
                            if (0 != (x.flags & TKFlags.KeyModUp))
                            {
                                _upTrigger = x;
                                _upArgs    = args;
                                _upKey     = key;
                            }
                            else
                            {
                                thc.trigger = x;
                            }
                        }

                        //AOutput.Write(key, mod);
                        if (0 != (x.flags & TKFlags.ShareEvent))
                        {
                            return(false);
                        }

                        if (thc.trigger == null)                          //KeyModUp or action==null
                        {
                            if (mod == KMod.Alt || mod == KMod.Win || mod == (KMod.Alt | KMod.Win))
                            {
                                //AOutput.Write("need Ctrl");
                                ThreadPool.QueueUserWorkItem(o => AKeys.Internal_.SendKey(KKey.Ctrl));                                 //disable Alt/Win menu
                            }
                        }
                        else if (mod != 0)
                        {
                            if (0 == (x.flags & TKFlags.NoModOff))
                            {
                                thc.muteMod = TriggerActionThreads.c_modRelease;
                            }
                            else if (mod == KMod.Alt || mod == KMod.Win || mod == (KMod.Alt | KMod.Win))
                            {
                                thc.muteMod = TriggerActionThreads.c_modCtrl;
                            }
                        }

                        _eatUp = key;
                        return(true);
                    }
                }
            }
            return(false);
        }