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; }
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); }
public static void Process(Keys keyData) { if (keyData == Keys.None) { return; } HotKeyData data = Cache[keyData]; data?.Invoke(); }
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; }
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); }
private static void RegisterLocal(HotKeyData keyData) { Cache.Add(keyData); }