void TextBox_KeyDown(object sender, KeyEventArgs e) { ++keyPressCount; var tempModKey = HotKeyStringConverter.GetModifierKey(e.SystemKey, e.Key); if (tempModKey != ModifierKeys.None) { modKey = tempModKey; } else { if (e.Key == Key.System) { regKey = e.SystemKey; } else { regKey = e.Key; } } RebuildHotkeyText(); e.Handled = true; }
/** * 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); } }
public OptionsWindow() { InitializeComponent(); HotKeyStringConverter.FromString(QuickCutsUI.Properties.Settings.Default.HotKeyString, out modKey, out regKey); RebuildHotkeyText(); }
void RebuildHotkeyText() { hotkeyString = HotKeyStringConverter.ToString(modKey, regKey); TextHotKey.Text = hotkeyString; }