Пример #1
0
        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;
            }
        }