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

            HotKeyData data = Cache[keyData];

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