Esempio n. 1
0
        private void AddShortcut()
        {
            if (shortcutList.SelectedItems.Count == 0)
            {
                return;
            }

            ListViewItem item = shortcutList.SelectedItems[0];

            if (item.SubItems.Count == 1)
            {
                item.SubItems.Add(shortcut.Text);
            }
            else
            {
                item.SubItems[1].Text = shortcut.Text;
            }

            HotKeyData hotKeyData = (HotKeyData)item.Tag;

            OnHotKeyRegister(new HotKeyRegistrationEventArgs(hotKeyData.Id, item.Text, shortcut.KeyData, hotKeyData.Action, hotKeyData.KeyData, hotKeyData.Global));

            hotKeyData.KeyData    = shortcut.KeyData;
            shortcutKeyNames.Text = shortcut.Text;
        }
Esempio n. 2
0
        private static void RegisterGlobal(HotKeyData keyData, IWin32Window window)
        {
            Keys keys = keyData.KeyData;

            ushort atom = NativeMethods.GlobalAddAtom(RegistrationSuffix + keys + DateTime.Now.Ticks);

            NativeMethods.RegisterHotKey(window.Handle, atom, GetModifierFlag(keys), (int)(keys & ~ModifierKeys));

            Cache.Add(keyData, atom);
        }
Esempio n. 3
0
        public static void Process(Keys keyData)
        {
            if (keyData == Keys.None)
            {
                return;
            }

            HotKeyData data = Cache[keyData];

            data?.Invoke();
        }
Esempio n. 4
0
        private void HandleShortcutListSelectedIndexChanged(object sender, EventArgs e)
        {
            ListView.SelectedListViewItemCollection items = shortcutList.SelectedItems;
            if (items.Count == 0 || items[0]?.Tag == null)
            {
                return;
            }

            HotKeyData hotKeyData = (HotKeyData)items[0].Tag;

            shortcut.Mode = hotKeyData.Global ? ShortcutMode.Global : ShortcutMode.Local;

            shortcut.KeyData = hotKeyData.KeyData;
        }
Esempio n. 5
0
        public static void UpdateHotKey(string id, Keys keyData)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException(nameof(id));
            }

            HotKeyData data = Cache.FirstOrDefault(hkd => hkd.Id == id);

            if (data == null)
            {
                return;
            }

            Cache.Remove(data.KeyData);
            data.KeyData = keyData;
            Cache.Add(data);
        }
Esempio n. 6
0
 private static void RegisterLocal(HotKeyData keyData)
 {
     Cache.Add(keyData);
 }