Пример #1
0
		/// <summary>
		/// Unhook the current key hook
		/// </summary>
		private void UnhookHotkeys()
		{
			// remove the hotkey hook
			if (m_hook != null)
			{
				m_hook.UnHook();
				m_hook = null;
			}
		}
Пример #2
0
		/// <summary>
		/// Hook the hot key for the authenticator
		/// </summary>
		/// <param name="config">current config settings</param>
		private void HookHotkeys()
		{
			// unhook any old hotkeys
			UnhookHotkeys();

			// hook hotkey
			List<WinAuthAuthenticator> keys = new List<WinAuthAuthenticator>();
			foreach (var auth in Config)
			{
				if (auth.HotKey != null)
				{
					keys.Add(auth);
				}
			}
			if (keys.Count != 0)
			{
				m_hook = new KeyboardHook(this, keys);
				m_hook.KeyPressed += new KeyboardHook.KeyboardHookEventHandler(Hotkey_KeyPressed);
			}
		}
Пример #3
0
        /// <summary>
        /// Click the OK button to save the keys
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void okButton_Click(object sender, EventArgs e)
        {
            WinAPI.VirtualKeyCode key = (keyCombo.SelectedItem as KeyItem != null ? ((KeyItem)keyCombo.SelectedItem).Key : default(WinAPI.VirtualKeyCode));
            if (key == 0)
            {
                this.Hotkey = null;
            }
            else if (this.Hotkey == null)
            {
                this.Hotkey = new HotKey();
            }

            if (this.Hotkey != null)
            {
                WinAPI.KeyModifiers modifiers = WinAPI.KeyModifiers.None;
                if (shiftToggle.Checked)
                {
                    modifiers |= WinAPI.KeyModifiers.Shift;
                }
                if (ctrlToggle.Checked)
                {
                    modifiers |= WinAPI.KeyModifiers.Control;
                }
                if (altToggle.Checked)
                {
                    modifiers |= WinAPI.KeyModifiers.Alt;
                }

                // check it is available if this is a different hotkey
                if ((key != this.Hotkey.Key || modifiers != this.Hotkey.Modifiers) && KeyboardHook.IsHotkeyAvailable(this, (Keys)key, modifiers) == false)
                {
                    WinAuthForm.ErrorDialog(this, strings.HotKeyNotAvailable);
                    this.DialogResult = System.Windows.Forms.DialogResult.None;
                    return;
                }

                this.Hotkey.Key       = key;
                this.Hotkey.Modifiers = modifiers;

                if (notifyRadioButton.Checked == true)
                {
                    this.Hotkey.Action   = HotKey.HotKeyActions.Notify;
                    this.Hotkey.Window   = null;
                    this.Hotkey.Advanced = null;
                }
                else if (injectRadioButton.Checked == true)
                {
                    this.Hotkey.Action   = HotKey.HotKeyActions.Inject;
                    this.Hotkey.Window   = this.injectTextbox.Text;
                    this.Hotkey.Advanced = null;
                }
                else if (pasteRadioButton.Checked == true)
                {
                    this.Hotkey.Action   = HotKey.HotKeyActions.Copy;
                    this.Hotkey.Window   = null;
                    this.Hotkey.Advanced = null;
                }
                else if (advancedRadioButton.Checked == true)
                {
                    this.Hotkey.Action   = HotKey.HotKeyActions.Advanced;
                    this.Hotkey.Window   = null;
                    this.Hotkey.Advanced = this.advancedTextbox.Text;
                }
            }
        }