private void SettingsRegisterHotkey(KeyEventArgs e, int id) { e.SuppressKeyPress = true; if (e.Modifiers != Keys.None) { Keys key = Keys.None; Hotkey.KeyModifiers modifiers = Hotkey.GetModifiers(e.KeyData, out key); if (key != Keys.None) { string mod = ""; string[] mSplit = modifiers.ToString().Split(new[] { ", " }, StringSplitOptions.None); foreach (string m in mSplit) { mod += m + "+"; } string hotkey = e.KeyData.ToString(); /* Almost 500 lines and only 10% done */ if (!config.hotkeys.Any(hotkey.Contains)) { switch (id) { case 0: textBox_hotkeySmoothOnOff.Text = mod + key; break; case 1: textBox_hotkeyOverlayOnOff.Text = mod + key; break; case 2: textBox_hotkeyToggleDisplay.Text = mod + key; break; case 3: textBox_hotkeyTabletMode.Text = mod + key; break; case 4: textBox_hotkeyStrengthUp.Text = mod + key; break; case 5: textBox_hotkeyStrengthDown.Text = mod + key; break; } config.hotkeys[id] = hotkey; mainForm.RegisterHotkey(mainForm.Handle, id, modifiers, key); } } } }
// Hotkey handling public void RegisterHotkey(IntPtr handle, int id, Hotkey.KeyModifiers modifiers, Keys key) { try { hotKeyHandling[id].Dispose(); } catch { // No hotkey to dispose? } try { hotKeyHandling[id] = new Hotkey(Handle, id, modifiers, key); switch (id) { case 0: hotKeyHandling[0].HotKeyPressed += new EventHandler(Hotkey_SmoothOnOff); break; case 1: hotKeyHandling[1].HotKeyPressed += new EventHandler(Hotkey_OverlayOnOff); break; case 2: hotKeyHandling[2].HotKeyPressed += new EventHandler(Hotkey_ToggleDisplay); break; case 3: hotKeyHandling[3].HotKeyPressed += new EventHandler(Hotkey_TabletMode); break; case 4: hotKeyHandling[4].HotKeyPressed += new EventHandler(Hotkey_StrengthUp); break; case 5: hotKeyHandling[5].HotKeyPressed += new EventHandler(Hotkey_StrengthDown); break; } } catch { // Hotkey registration failed } }
public static extern bool RegisterHotKey(IntPtr hWnd, int id, Hotkey.KeyModifiers fsModifiers, Keys vk);