コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: cj3j/QuickCuts
        /**
         * Reads the hotkey string from settings and registers the hotkey combo with windows
         */
        void InitHotkey()
        {
            if (keyHook != null)
            {
                keyHook.UnregisterHotKey();
                keyHook = null;
            }

            var          hotKeyString = QuickCutsUI.Properties.Settings.Default.HotKeyString;
            ModifierKeys modKey;
            Key          regKey;

            if (HotKeyStringConverter.FromString(hotKeyString, out modKey, out regKey))
            {
                try
                {
                    keyHook = new WpfApplicationHotKey.HotKey(modKey, regKey, this);
                    keyHook.HotKeyPressed += new Action <WpfApplicationHotKey.HotKey>(keyHook2_HotKeyPressed);
                }
                catch (Exception ex)
                {
                    var button = MessageBoxButton.OK;
                    var icon   = MessageBoxImage.Warning;
                    MessageBox.Show(this, String.Format("Could not register hotkey '{0}'. {1}", hotKeyString, ex.Message), "Error", button, icon);
                }
            }
            else
            {
                var button = MessageBoxButton.OK;
                var icon   = MessageBoxImage.Warning;
                MessageBox.Show(this, String.Format("Could not load hotkey '{0}'.", hotKeyString), "Error", button, icon);
            }
        }
コード例 #2
0
        public OptionsWindow()
        {
            InitializeComponent();

            HotKeyStringConverter.FromString(QuickCutsUI.Properties.Settings.Default.HotKeyString, out modKey, out regKey);

            RebuildHotkeyText();
        }