예제 #1
0
        private void hotkeyMenuItem_Click(object sender, EventArgs args)
        {
            ModifierKeys? newModifiers;
            Keys? newKey;
            var hotkeyChanged = PromptForHotkey(out newModifiers, out newKey);
            if (! hotkeyChanged)
                return;

            if (keyboardHook != null)
            {
                keyboardHook.Dispose();
                keyboardHook = null;
            }

            Settings.Default.UseHotkey = newKey != null && newModifiers != null;
            if (Settings.Default.UseHotkey)
            {
                Settings.Default.HotkeyModifiers = (int) newModifiers.Value;
                Settings.Default.HotkeyKey = (int) newKey.Value;

                RegisterHotkeyFromSettings();
            }
            else
            {
                Settings.Default.HotkeyModifiers = 0;
                Settings.Default.HotkeyKey = 0;
            }

            UpdateHotkeyMenuItemFromSettings();
        }
예제 #2
0
 private void RegisterHotkeyFromSettings()
 {
     keyboardHook = new KeyboardHook();
     keyboardHook.KeyPressed += (s, a) =>
     {
         SwapButtons();
         var handedness = swapper.IsSwapped ? Resources.LeftHanded : Resources.RightHanded;
         notifyIcon.ShowBalloonTip(2000, Resources.SwappedEventBaloonTitle, handedness, ToolTipIcon.Info);
     };
     keyboardHook.RegisterHotKey((ModifierKeys) Settings.Default.HotkeyModifiers,
         (Keys)Settings.Default.HotkeyKey);
 }