示例#1
0
        private IntPtr WndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            // address the messages you are receiving using msg, wParam, lParam
            if (msg == WM_HOTKEY)
            {
                short hkeyid = (short)wParam;
                if (keyIDs.ContainsKey(hkeyid))
                {
                    if (HotKeyPressed != null)
                    {
                        int key = (int)(((int)lParam >> 16) & 0xFFFF);
                        AccessModifierKeys modifier = (AccessModifierKeys)((int)lParam & 0xFFFF);

                        HotKeyPressed(this, new HotKeyEventArgs(modifier, KeyInterop.KeyFromVirtualKey(key)));
                    }
                }
            }
            return(IntPtr.Zero);
        }
示例#2
0
        public void RegisterHotKey(AccessModifierKeys modifiers, Key key)
        {
            // Generates unique ID
            string atomName = modifiers.ToString() + key.ToString() + this.GetType().FullName;
            short  hKeyID   = GlobalAddAtom(atomName);

            ModifierKeys = modifiers;

            if (hKeyID != 0)
            {
                if (!RegisterHotKey(Handle, hKeyID, (int)modifiers, KeyInterop.VirtualKeyFromKey(key)))
                {
                    throw new ArgumentException("Hotkey combination could not be registered.");
                }
                else
                {
                    keyIDs.Add(hKeyID, hKeyID);
                }
            }
            else
            {
                throw new ArgumentException("Hotkey ID not generated!");
            }
        }
示例#3
0
 public HotKeyEventArgs(AccessModifierKeys pModKeys, Key pKey)
 {
     ModifierKeys = pModKeys;
     Key = pKey;
 }
示例#4
0
        public void RegisterHotKey(AccessModifierKeys modifiers, Key key)
        {
            // Generates unique ID
            string atomName = modifiers.ToString() + key.ToString() + this.GetType().FullName;
            short hKeyID = GlobalAddAtom(atomName);
            ModifierKeys = modifiers;

            if (hKeyID != 0) {
                if (!RegisterHotKey(Handle, hKeyID, (int)modifiers, KeyInterop.VirtualKeyFromKey(key)))
                    throw new ArgumentException("Hotkey combination could not be registered.");
                else
                    keyIDs.Add(hKeyID, hKeyID);
            }
            else
                throw new ArgumentException("Hotkey ID not generated!");
        }
示例#5
0
 public HotKeyEventArgs(AccessModifierKeys pModKeys, Key pKey)
 {
     ModifierKeys = pModKeys;
     Key          = pKey;
 }