public static HotKey RegisterHotKey(IList <string> keys, Action <HotKey> action) { Key key = Key.None; Enum.TryParse(keys[0], out HotKeyModifier mod1); HotKeyModifier mod2 = HotKeyModifier.None; if (keys.Count > 2) { Enum.TryParse(keys[1], out mod2); Enum.TryParse(keys[2], out key); } else if (keys.Count == 2) { Enum.TryParse(keys[1], out key); } HotKey hotkey = null; if (mod1 != HotKeyModifier.None && mod2 != HotKeyModifier.None && key != Key.None) { hotkey = new HotKey(key, mod2 | mod1, action); } else if (mod1 != HotKeyModifier.None && key != Key.None) { hotkey = new HotKey(key, mod1, action); } return(hotkey); }
/// <summary> /// Creates a new HotKey object. /// </summary> /// <param name="key">Key.</param> /// <param name="modifiers">Key modifiers.</param> /// <param name="id">Hotkey ID.</param> /// <param name="handler">Hotkey event handler.</param> public HotKey(Keys key, HotKeyModifier modifiers, int id, HotKeyEventHandler handler) { m_id = id; m_modifier = modifiers; m_key = key; m_handler = handler; }
/// <summary> /// Initializes a new instance of the <see cref="HotKey"/> class. /// </summary> /// <param name="modifierKey">The modifier key.</param> /// <param name="secondModifierKey">The second modifier key.</param> /// <param name="key">The key value.</param> public HotKey(HotKeyModifier modifierKey, HotKeyModifier secondModifierKey, Framework.Enums.HotKey key) { this.ModifierKey = modifierKey; this.SecondModifierKey = secondModifierKey; this.Key = key; this.Registered = false; }
public Int32 Register(HotKeyModifier hotKeyModifier, Key hotKey, [NotNull] Action action) { this.CheckBinding(); var virtualkeyCode = KeyInterop.VirtualKeyFromKey(hotKey); return(base.Register(this.windowHandle.Handle, hotKeyModifier, (UInt32)virtualkeyCode, action)); }
public HotKey(Key k, HotKeyModifier keyModifiers, Action<HotKey> action, bool register = true) { Key = k; Modifiers = keyModifiers; Action = action; if (register) { Register(); } }
public HotKey(Key k, HotKeyModifier keyModifiers, Action <HotKey> action, bool register = true) { Key = k; Modifiers = keyModifiers; Action = action; if (register) { Register(); } }
public void Unregister(HotKeyModifier hotKeyModifier, UInt32 virtualKeyCode) { this.CheckDisposed(); var hotKeyId = this.FindHotKeyId(hotKeyModifier, virtualKeyCode); if (hotKeyId.HasValue) { this.Unregister(hotKeyId.Value); } }
private GlobalHotKey(IntPtr windowHandle, [NotNull] GlobalAtom globalAtom, HotKeyModifier hotKeyModifier, UInt32 virtualKeyCode) { if (globalAtom == null) { throw new ArgumentNullException(nameof(globalAtom)); } this.WindowHandle = windowHandle; this.globalAtom = globalAtom; this.HotKeyModifier = hotKeyModifier; this.VirtualKeyCode = virtualKeyCode; }
public HotKeySpec(bool unkBool, bool unkBool2, HotKeyModifier modifier, InGameHotKey eventId, DIK primaryKeyCode, bool primaryOnDown, DIK secondaryKeyCode, bool secondaryOnDown) { this.unkBool = unkBool; this.unkBool2 = unkBool2; this.modifier = modifier; this.eventId = eventId; this.primaryKeyCode = primaryKeyCode; this.primaryOnDown = primaryOnDown; this.secondaryKeyCode = secondaryKeyCode; this.secondaryOnDown = secondaryOnDown; }
/// <summary> /// Registers a new hotkey. /// </summary> /// <param name="key">Key.</param> /// <param name="modifier">Key modifiers.</param> /// <param name="id">Hotkey ID.</param> /// <param name="handler">Hotkey event handler.</param> /// <returns>True if hotkey was registered, otherwise false.</returns> public bool Register(Keys key, HotKeyModifier modifier, int id, HotKeyEventHandler handler) { // attempt to register the hotkey. bool result = RegisterHotKey(m_ctrl.Handle, id, (int)modifier, (int)key); // add the hotkey to the collection. if (result) { m_keys.Add(new HotKey(key, modifier, id, handler)); } return(result); }
public static GlobalHotKey Register(IntPtr windowHandle, HotKeyModifier hotKeyModifier, UInt32 virtualKeyCode) { if (windowHandle == IntPtr.Zero) { throw new ArgumentNullException(nameof(windowHandle)); } if (hotKeyModifier == HotKeyModifier.None) { throw new ArgumentOutOfRangeException(nameof(hotKeyModifier)); } return(GlobalHotKey.RegisterCore(windowHandle, hotKeyModifier, virtualKeyCode)); }
protected Int32 Register(IntPtr windowHandle, HotKeyModifier hotKeyModifier, UInt32 virtualkeyCode, [NotNull] Action action) { this.CheckDisposed(); if (action == null) { throw new ArgumentNullException(nameof(action)); } var hotKey = GlobalHotKey.Register(windowHandle, hotKeyModifier, virtualkeyCode); this.registeredHotKeys.Add(hotKey, action); return(hotKey.Id); }
public Boolean HandleHotKey(HotKeyModifier hotKeyModifier, UInt32 virtualKeyCode) { this.CheckDisposed(); var registeredHotKey = this.registeredHotKeys.SingleOrDefault(hotKey => hotKey.Key.Equals(hotKeyModifier, virtualKeyCode)); if (registeredHotKey.Key != null) { registeredHotKey.Value(); return(true); } return(false); }
private static GlobalHotKey RegisterCore(IntPtr windowHandle, HotKeyModifier hotKeyModifier, UInt32 virtualKeyCode) { if (hotKeyModifier == HotKeyModifier.None) { throw new ArgumentException(String.Empty, nameof(hotKeyModifier)); } var globalAtomName = Guid.NewGuid().ToString(); var globalAtom = (GlobalAtom)GlobalAtom.CreateNew(globalAtomName); var registerHotKeyResult = NativeMethods.RegisterHotKey(windowHandle, globalAtom.Id, (UInt32)hotKeyModifier, virtualKeyCode); var lastWin32Error = Marshal.GetLastWin32Error(); if (!registerHotKeyResult) { // It is possible that the next line throws... globalAtom.Delete(); throw new Win32Exception(lastWin32Error); } return(new GlobalHotKey(windowHandle, globalAtom, hotKeyModifier, virtualKeyCode)); }
/// <summary> /// Registers the supplied hot key and returns a value indicating the registration was successful. /// The hot key will be unregistered before the method returns. /// </summary> /// <param name="hotKeyModifier">The associated <see cref="HotKey.HotKeyModifier"/>.</param> /// <param name="virtualKeyCode">The associated virtual key code.</param> /// <returns>A value, indicating whether, the hot key is unused.</returns> public static Boolean Probe(HotKeyModifier hotKeyModifier, UInt32 virtualKeyCode) { if (hotKeyModifier == HotKeyModifier.None) { throw new ArgumentException(String.Empty, nameof(hotKeyModifier)); } try { using (RegisterCore(IntPtr.Zero, hotKeyModifier, virtualKeyCode)) { return(true); } } catch (Win32Exception win32Exception) { if (win32Exception.NativeErrorCode == (Int32)NativeMethods.HotKeyErrorCode.ERROR_HOTKEY_ALREADY_REGISTERED) { return(false); } throw; } }
public void Unregister(HotKeyModifier hotKeyModifier, Key hotKey) { var virtualkeyCode = KeyInterop.VirtualKeyFromKey(hotKey); base.Unregister(hotKeyModifier, (UInt32)virtualkeyCode); }
public static extern bool RegisterHotKey(IntPtr hWnd, int id, HotKeyModifier fsModifiers, Framework.Enums.HotKey vlc);
/// <summary> /// Checks if <c>this</c> contains the supplied modifier and virtual key code. /// </summary> /// <param name="hotKeyModifier">The modifier keys.</param> /// <param name="virtualKeyCode">The virtual key code.</param> /// <returns><c>True</c> if <paramref name="hotKeyModifier"/> and <paramref name="virtualKeyCode"/> match, otherweise <c>false</c>.</returns> public Boolean Equals(HotKeyModifier hotKeyModifier, UInt32 virtualKeyCode) { return(this.VirtualKeyCode == virtualKeyCode && this.HotKeyModifier == hotKeyModifier); }
public Int32?FindHotKeyId(HotKeyModifier hotKeyModifier, UInt32 virtualKeyCode) { return(base.FindHotKeyId(hotKeyModifier, virtualKeyCode)); }
/// <summary> /// Initializes a new instance of the <see cref="ActionHotKey"/> class. /// </summary> /// <param name="firstModifier">The first modifier.</param> /// <param name="secondModifier">The second modifier.</param> /// <param name="hotKey">The hot key.</param> public ActionHotKey(HotKeyModifier firstModifier, HotKeyModifier secondModifier, HotKey hotKey) { this.HotKey = hotKey; this.FirstModifier = firstModifier; this.SecondModifier = secondModifier; }
public Int32 Register(DummyWindow dummyWindow, HotKeyModifier hotKeyModifier, UInt32 virtualKeyCode, Action action) { return(this.Register(dummyWindow.WindowHandle, hotKeyModifier, virtualKeyCode, action)); }
/// <summary> /// Registers a new hotkey. /// </summary> /// <param name="key">Key.</param> /// <param name="modifier">Key modifiers.</param> /// <param name="id">Hotkey ID.</param> /// <param name="handler">Hotkey event handler.</param> /// <returns>True if hotkey was registered, otherwise false.</returns> public bool Register(Keys key, HotKeyModifier modifier, int id, HotKeyEventHandler handler) { // attempt to register the hotkey. bool result = RegisterHotKey(m_ctrl.Handle, id, (int)modifier, (int)key); // add the hotkey to the collection. if (result) m_keys.Add(new HotKey(key, modifier, id, handler)); return result; }
protected static Boolean ProbeHotKey(HotKeyModifier hotKeyModifier, UInt32 virtualkeyCode) { return(GlobalHotKey.Probe(hotKeyModifier, virtualkeyCode)); }
protected Int32?FindHotKeyId(HotKeyModifier hotKeyModifier, UInt32 virtualKeyCode) { this.CheckDisposed(); return(this.registeredHotKeys.SingleOrDefault(hotKey => hotKey.Key.HotKeyModifier == hotKeyModifier && hotKey.Key.VirtualKeyCode == virtualKeyCode).Key?.Id); }
public static Boolean ProbeHotKey(HotKeyModifier hotKeyModifier, Key hotKey) { var virtualkeyCode = KeyInterop.VirtualKeyFromKey(hotKey); return(HotKeyManager.ProbeHotKey(hotKeyModifier, (UInt32)virtualkeyCode)); }