예제 #1
0
파일: Settings.cs 프로젝트: skazz0r/eve-plh
        private static void SetupShortcut(IKeyboardHook hook, string shortcutId, string shortcutKeys, ShortcutPressed action)
        {
            if (string.IsNullOrEmpty(shortcutKeys))
            {
                hook.UnregisterGlobalShortcut(shortcutId);
                return;
            }

            var keyPress = KeyExtensions.ToKeyPress(shortcutKeys);

            try
            {
                hook.RegisterGlobalShortcut(shortcutId, keyPress.Modifier, keyPress.Key);
            }
            catch (Exception e)
            {
                MessageBox.Show(
                    Application.Current.MainWindow,
                    string.Format("Could not register global shortcut: {0}", e.Message),
                    "WARNING");
                return;
            }
            if (hook[shortcutId] == null)
            {
                hook[shortcutId] += action;
            }
        }
예제 #2
0
        /// <summary>
        /// determine what should happen if a HotKey got pressed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HotKeyPressed(object sender, KeyPressedEventArgs e)
        {
            Shortcut result;
            var      jamesHotKey = _managerSettings.JamesHotKey.HotKey;

            if (e.HotKey.Key == jamesHotKey.Key && e.HotKey.Modifiers == jamesHotKey.ModifierKeys)
            {
                result = _managerSettings.JamesHotKey;
            }
            else
            {
                result = _managerSettings.Shortcuts.FirstOrDefault(key => key.HotKey.Key == e.HotKey.Key && key.HotKey.ModifierKeys == e.HotKey.Modifiers);
            }
            ShortcutPressed?.Invoke(result, new EventArgs());
        }