public void SetHotKey(GLOBAL_HOT_KEY_TYPE type, HotKeySetting new_setting) { var cur_item = GetHotKeyItem(type); try { if (new_setting.key == cur_item.setting.key && new_setting.modifiers == cur_item.setting.modifiers) { return; } cur_item.setting = new_setting; if (new_setting.key == Key.None) { cur_item.hot_key?.Unregister(); return; } if (cur_item.hot_key == null) { cur_item.hot_key = new GlobalHotKey(new_setting.key, new_setting.modifiers, GlobalHotKeyPressed); } else { cur_item.hot_key.UpdateHotKey(new_setting.key, new_setting.modifiers); } } catch (Exception ex) { MessageBox.Show("Unable to set global hotkey due to: " + ex.Message); } }
private void SetHotKeyFromWindow(GLOBAL_HOT_KEY_TYPE type, CheckBox alt_box, CheckBox cntrl_box, CheckBox shift_box, CheckBox win_box, TextBox txt_box) { System.Windows.Input.Key hot_key = System.Windows.Input.Key.None; var hot_key_modifier = UnManaged.KeyModifier.None; if (alt_box.IsChecked == true) { hot_key_modifier |= UnManaged.KeyModifier.Alt; } if (cntrl_box.IsChecked == true) { hot_key_modifier |= UnManaged.KeyModifier.Ctrl; } if (shift_box.IsChecked == true) { hot_key_modifier |= UnManaged.KeyModifier.Shift; } if (win_box.IsChecked == true) { hot_key_modifier |= UnManaged.KeyModifier.Win; } if (!String.IsNullOrWhiteSpace(txt_box.Text)) { var key = txt_box.Text.ToUpper(); if (key[0] >= 0 && key[0] <= 9) { key = "D" + key; } Enum.TryParse <System.Windows.Input.Key>(key, out hot_key); } broker.SetHotKey(type, new Broker.HotKeySetting { modifiers = hot_key_modifier, key = hot_key }); }
private void SetHotKeyFormFromSetting(GLOBAL_HOT_KEY_TYPE type, CheckBox alt_box, CheckBox cntrl_box, CheckBox shift_box, CheckBox win_box, TextBox txt_box) { var setting = broker.GetHotKeySetting(type); alt_box.IsChecked = setting.modifiers.HasFlag(UnManaged.KeyModifier.Alt); shift_box.IsChecked = setting.modifiers.HasFlag(UnManaged.KeyModifier.Shift); cntrl_box.IsChecked = setting.modifiers.HasFlag(UnManaged.KeyModifier.Ctrl); win_box.IsChecked = setting.modifiers.HasFlag(UnManaged.KeyModifier.Win); var key_char = setting.key.ToString(); if (setting.key == System.Windows.Input.Key.None) { key_char = ""; } key_char = key_char.Replace("NumPad", "").Replace("Oem", ""); if (key_char.Length == 2) { key_char = key_char.Replace("D", ""); } if (key_char.Length > 1) { key_char = ""; } txt_box.Text = key_char; }
private HotKeyItem GetHotKeyItem(GLOBAL_HOT_KEY_TYPE type) { if (!hot_keys.TryGetValue(type, out var cur)) { hot_keys[type] = cur = new HotKeyItem { setting = new HotKeySetting { key = Key.None } } } ; return(cur); }
private void SetHotKeyFromSetting(GLOBAL_HOT_KEY_TYPE type, String hotkey_setting_str) { if (!String.IsNullOrWhiteSpace(hotkey_setting_str)) { try { var new_hotkey = Newtonsoft.Json.JsonConvert.DeserializeObject <HotKeySetting>(hotkey_setting_str); if (new_hotkey != null) { SetHotKey(type, new_hotkey); } } catch (Exception) { } } }
public HotKeySetting GetHotKeySetting(GLOBAL_HOT_KEY_TYPE type) => GetHotKeyItem(type).setting;