예제 #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;
        }
예제 #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);
        }
예제 #3
0
        public static void Process(Keys keyData)
        {
            if (keyData == Keys.None)
            {
                return;
            }

            HotKeyData data = Cache[keyData];

            data?.Invoke();
        }
예제 #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;
        }
예제 #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);
        }
예제 #6
0
 private static void RegisterLocal(HotKeyData keyData)
 {
     Cache.Add(keyData);
 }