Esempio n. 1
0
 void _UpClear()
 {
     _upTrigger = null;
     _upArgs    = null;
     _upKey     = 0;
 }
Esempio n. 2
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);
        }