public void RegisterHotkey(HotkeyInfo hotkeyInfo) { if (hotkeyInfo != null && hotkeyInfo.Status != HotkeyStatus.Registered) { if (!hotkeyInfo.IsValidHotkey) { hotkeyInfo.Status = HotkeyStatus.NotConfigured; return; } if (hotkeyInfo.ID == 0) { string uniqueID = Helpers.GetUniqueID(); hotkeyInfo.ID = NativeMethods.GlobalAddAtom(uniqueID); if (hotkeyInfo.ID == 0) { DebugHelper.WriteLine("Unable to generate unique hotkey ID: " + hotkeyInfo); hotkeyInfo.Status = HotkeyStatus.Failed; return; } } if (!NativeMethods.RegisterHotKey(Handle, hotkeyInfo.ID, (uint)hotkeyInfo.ModifiersEnum, (uint)hotkeyInfo.KeyCode)) { NativeMethods.GlobalDeleteAtom(hotkeyInfo.ID); DebugHelper.WriteLine("Unable to register hotkey: " + hotkeyInfo); hotkeyInfo.ID = 0; hotkeyInfo.Status = HotkeyStatus.Failed; return; } hotkeyInfo.Status = HotkeyStatus.Registered; } }
private void HotkeyProc(HotkeyInfo hotkeyInfo) { logTextBox.Text += string.Format("{0} : Hotkey Proc! {1}, {2}{3}", DateTime.Now.ToString("hh:MM:ss.fff"), hotkeyInfo.Key, hotkeyInfo.Modifiers, Environment.NewLine); logTextBox.Select(logTextBox.Text.Length, 0); logTextBox.ScrollToCaret(); }
public HotkeySettings(HotkeyType job, Keys hotkey = Keys.None) : this() { TaskSettings = TaskSettings.GetDefaultTaskSettings(); TaskSettings.Job = job; TaskSettings.Description = job.GetDescription(); HotkeyInfo = new HotkeyInfo { Hotkey = hotkey }; }
public HotkeyInfo RegisterHotkey(HotkeyInfo hotkeyInfo) { if (hotkeyInfo != null && hotkeyInfo.Status != HotkeyStatus.Registered) { if (hotkeyInfo.ID > 0) { return RegisterHotkey(hotkeyInfo.Hotkey, hotkeyInfo.HotkeyPress, hotkeyInfo.ID); } else { return RegisterHotkey(hotkeyInfo.Hotkey, hotkeyInfo.HotkeyPress); } } return hotkeyInfo; }
private void HotkeyProc(HotkeyInfo hotkeyInfo) { Console.WriteLine("{0} : Hotkey Proc! {1}, {2}{3}", DateTime.Now.ToString("hh:MM:ss.fff"), hotkeyInfo.Key, hotkeyInfo.Modifiers, Environment.NewLine); if (hotkeyInfo.Key == Keys.F5) { rebuildGroups(); } else { foreach (ProgramGroup group in Program.PGM.programGroups) { group.isThisYourKotkey(hotkeyInfo); } } updateDisplayedVolume(); }
public void RegisterHotkey(Hotkey hotkey, Action <Hotkey> action) { if (action == null) { throw new ArgumentNullException(nameof(action)); } if (registeredHotkeys.ContainsKey(hotkey)) { return; } HotkeyInfo hi = new HotkeyInfo(); hi.Hotkey = hotkey; hi.Action = action; hi.WindowHandle = IntPtr.Zero; string uniqueID = Guid.NewGuid().ToString("N"); hi.ID = NativeMethods.GlobalAddAtom(uniqueID); if (hi.ID == 0) { throw new Exception($"Failed to create unique ID for hotkey {hotkey}", new Win32Exception(Marshal.GetLastWin32Error())); } var modifiers = ModifiersFromHotkey(hi.Hotkey); var keycode = hi.Hotkey.KeyCode & Keys.KeyCode; if (NativeMethods.RegisterHotKey(hi.WindowHandle, hi.ID, modifiers, (uint)keycode)) { registeredHotkeys.Add(hotkey, hi); } else { int error = Marshal.GetLastWin32Error(); // Cleanup atom NativeMethods.GlobalDeleteAtom(hi.ID); hi.ID = 0; throw new Exception($"Failed to register hotkey {hotkey}", new Win32Exception(error)); } }
public override bool Equals(System.Object obj) { // If parameter is null return false. if (obj == null) { return(false); } // If parameter cannot be cast to Point return false. HotkeyInfo p = obj as HotkeyInfo; if ((System.Object)p == null) { return(false); } // Return true if the fields match: return((modifier == p.Modifiers) && (key == p.Key)); }
public void SetHotkeyInfo(HotkeyInfo hotkey) { this.Hotkey = hotkey.keyCode; if (hotkey.shift) { this.HotkeyModifiers = this.HotkeyModifiers | Keys.Shift; } if (hotkey.alt) { this.HotkeyModifiers = this.HotkeyModifiers | Keys.Alt; } if (hotkey.control) { this.HotkeyModifiers = this.HotkeyModifiers | Keys.Control; } }
/// <summary> /// Catches Windows' message about pressed hotkey /// and fires up the HandleHotkey method /// </summary> /// <param name="m"></param> protected override void WndProc(ref Message m) { // we check if the message is about out hotkey var hotkeyInfo = HotkeyInfo.GetFromMessage(m); if (hotkeyInfo != null) { string command = null; foreach (GlobalHotkey gh in this.ghList) { if (gh.Key.Equals((int)hotkeyInfo.Key)) { command = gh.command; } } this.HandleHotkey(hotkeyInfo, command); } base.WndProc(ref m); }
/* * This function is called with info on what hotkey was pressed, * if the hotkey that was pressed belongs to this group then it * performs the appropriate task */ public void isThisYourKotkey(HotkeyInfo hotkeyInfo) { if (!hasHotkey) { return; } if (hotkeyInfo.Key == (Keys)hotkeyVolUp.Key && hotkeyInfo.Modifiers == (Modifiers)hotkeyVolUp.Modifier) { //volAsPercent += 5; setVolume(volAsPercent + 5); } if (hotkeyInfo.Key == (Keys)hotkeyVolDown.Key && hotkeyInfo.Modifiers == (Modifiers)hotkeyVolDown.Modifier) { //volAsPercent -= 5; setVolume(volAsPercent - 5); } updateVolume(); }
public bool UnregisterHotkey(HotkeyInfo hotkeyInfo) { if (hotkeyInfo != null) { if (hotkeyInfo.ID > 0) { bool result = NativeMethods.UnregisterHotKey(Handle, hotkeyInfo.ID); if (result) { NativeMethods.GlobalDeleteAtom(hotkeyInfo.ID); hotkeyInfo.ID = 0; hotkeyInfo.Status = HotkeyStatus.NotConfigured; return true; } } hotkeyInfo.Status = HotkeyStatus.Failed; } return false; }
/* * private void KeybindingPrompt_KeyPress(object sender, KeyPressEventArgs e) * { * Console.WriteLine("A KEY WAS PRESSED!!!!! : "+ e.KeyChar+ " string: "+ e.ToString() ); * //this.Dispose(); * }*/ protected override void WndProc(ref Message m) { Console.WriteLine("something happened!"); if (m.Msg == 0x101) { m.LParam = (IntPtr)((int)m.WParam * (int)Math.Pow(16, 4)); Console.WriteLine(m.WParam); Console.WriteLine(m.LParam); m.Msg = Win32.WM_HOTKEY_MSG_ID; } var hotkeyInfo = HotkeyInfo.GetFromMessage(m); if (m.Msg == 0x101 || m.Msg == Win32.WM_HOTKEY_MSG_ID) { Console.WriteLine(m.ToString()); Console.WriteLine("Detected!"); } if (hotkeyInfo != null) { HotkeyProc(hotkeyInfo); } base.WndProc(ref m); }
public static bool loadConfig(string module, Expandable.IConfig config, Hotkey[] hks) { string file = module == CORE_ID ? CORE_CONFIG_PATH : CONFIG_PATH + module + ".ini"; if (!File.Exists(file)) { return(false); } Config tmp = new Config(); using (Stream str = File.OpenRead(file)) { try { XmlSerializer xs = new XmlSerializer(typeof(Config)); tmp = (Config)xs.Deserialize(str); } catch (Exception e) { MessageBox.Show(e.Message); } } if (tmp.Properties.Count == 0 && tmp.Hotkeys.Count == 0) { return(false); } if (tmp.Hotkeys.Count > 0) { for (int i = 0; i < hks.Length; i++) { HotkeyInfo hki = tmp.Hotkeys.FirstOrDefault(_ => _.id == hks[i].id); if (hki.id != null) { hks[i].keys = hki.keys; } } } if (tmp.Properties.Count > 0) { Type confType = config.GetType(); FieldInfo[] fields = confType.GetFields(); foreach (FieldInfo fi in fields) { object value = tmp.Properties.FirstOrDefault(_ => _.name == fi.Name).value; if (value == null) { continue; } if (value.GetType().AssemblyQualifiedName == fi.FieldType.AssemblyQualifiedName) { fi.SetValue(config, value); } } } return(true); }
public HotkeyEventArgs(Hotkey hotkey, HotkeyInfo info) { HotkeyInfo = info; Hotkey = hotkey; }
public HotkeySettings(HotkeyType job, Keys hotkey = Keys.None) : this() { TaskSettings = TaskSettings.GetDefaultTaskSettings(); TaskSettings.Job = job; HotkeyInfo = new HotkeyInfo(hotkey); }
public bool UnregisterHotkey(HotkeyInfo hotkeyInfo) { if (hotkeyInfo != null) { bool result = UnregisterHotkey(hotkeyInfo.ID); if (result) { hotkeyInfo.Status = HotkeyStatus.NotConfigured; } else { hotkeyInfo.Status = HotkeyStatus.Failed; } HotkeyList.Remove(hotkeyInfo); return result; } return false; }
public void UpdateHotkey(HotkeyInfo hotkeyInfo) { HotkeyInfo = hotkeyInfo; UpdateHotkeyText(); }
public HotkeySettings() { HotkeyInfo = new HotkeyInfo(); }
public HotkeyInfo UpdateHotkey(HotkeyInfo hotkeyInfo) { UnregisterHotkey(hotkeyInfo); return RegisterHotkey(hotkeyInfo); }
public void Reset() { EditingHotkey = false; HotkeyInfo = new HotkeyInfo(); SetDefaultButtonText(); }
private HotkeyInfo RegisterHotkey(Keys hotkey, Action hotkeyPress, ushort id) { HotkeyInfo hotkeyInfo = new HotkeyInfo(hotkey, hotkeyPress, id); if (!hotkeyInfo.IsValidHotkey) { hotkeyInfo.Status = HotkeyStatus.NotConfigured; return hotkeyInfo; } if (id == 0) { DebugHelper.WriteLine("Unable to generate unique hotkey ID: " + hotkeyInfo); hotkeyInfo.Status = HotkeyStatus.Failed; return hotkeyInfo; } if (IsHotkeyExist(hotkey)) { DebugHelper.WriteLine("Hotkey already exist: " + hotkeyInfo); hotkeyInfo.Status = HotkeyStatus.Failed; return hotkeyInfo; } if (!NativeMethods.RegisterHotKey(Handle, (int)id, (uint)hotkeyInfo.ModifiersEnum, (uint)hotkeyInfo.KeyCode)) { NativeMethods.GlobalDeleteAtom(id); DebugHelper.WriteLine("Unable to register hotkey: " + hotkeyInfo); hotkeyInfo.Status = HotkeyStatus.Failed; return hotkeyInfo; } HotkeyList.Add(hotkeyInfo); hotkeyInfo.Status = HotkeyStatus.Registered; return hotkeyInfo; }
private void UpdateHotkeyText() { Text = HotkeyInfo.ToString(); Invalidate(); }
public HotkeySettings(CaptureType job, Keys hotkey = Keys.None) : this() { Job = job; HotkeyInfo = new HotkeyInfo(hotkey); }
private void LoadDefaults() { PersonnalFolder = DefaultPersonnalFolder; AreaHotkey = DefaultAreaHotkey; ClipboardHotkey = DefaultClipboardHotkey; }
private void HotkeyProc(HotkeyInfo hotkeyInfo) { Native.SetMonitorEnable(this.Handle, true); Application.Exit(); }
public HotkeySettings() { HotkeyInfo = new HotkeyInfo(); Job = CaptureType.None; }