示例#1
0
            public override bool Equals(object obj)
            {
                if (!(obj is HookKey))
                {
                    return(false);
                }
                HookKey other = (HookKey)obj;

                return(ReferenceEquals(Method, other.Method) && ReferenceEquals(Hook, other.Hook));
            }
示例#2
0
        public static void Add(MethodBase method, Delegate hookDelegate)
        {
            HookKey      key = new HookKey(method, hookDelegate);
            Stack <Hook> hooks;

            if (!_HookMap.TryGetValue(key, out hooks))
            {
                _HookMap[key] = hooks = new Stack <Hook>();
            }

            Hook hook = new Hook(method, hookDelegate);

            hooks.Push(hook);
        }
        private bool RegisterKey( int modifier, int keyCode )
        {
            int id;
            HookKey hk = new HookKey( modifier, keyCode );

            if( !_dic.ContainsKey( hk ) )
            {
                HotKeyHook.Register( _interopHelper.Handle, modifier, keyCode, out id );
                _dic.Add( hk, id );
                return true;
            }

            return false;
        }
示例#4
0
        public static void Remove(MethodBase method, Delegate hookDelegate)
        {
            HookKey      key = new HookKey(method, hookDelegate);
            Stack <Hook> hooks;

            if (!_HookMap.TryGetValue(key, out hooks))
            {
                throw new KeyNotFoundException($"No hooks for {method} -> {hookDelegate} found");
            }

            hooks.Pop().Undo();

            if (hooks.Count == 0)
            {
                _HookMap.Remove(key);
            }
        }
示例#5
0
        public static void Remove(MethodBase method, Delegate hookDelegate)
        {
            HookKey      key = new HookKey(method, hookDelegate);
            Stack <Hook> hooks;

            if (!_HookMap.TryGetValue(key, out hooks))
            {
                return;
            }

            hooks.Pop().Undo();
            hooks.Pop().Free();

            if (hooks.Count == 0)
            {
                _HookMap.Remove(key);
            }
        }
示例#6
0
    public void AddHook(Hook hook, string ruleName, string code)
    {
        Debug.Assert(code != null);
        List <string> codes;

        if (code.StartsWith("`"))
        {
            code = code.Substring(1, code.Length - 2);
        }

        var key = new HookKey(hook, ruleName);

        if (!m_hooks.TryGetValue(key, out codes))
        {
            codes = new List <string>();
            m_hooks.Add(key, codes);
        }

        codes.Add(code);
    }