UIKeyModifierFlags UIKeyModifierFlagsFrom(HardwareKeyModifierKeys modifierKeys) { var flags = (UIKeyModifierFlags)0; if (((HardwareKeyModifierKeys)modifierKeys & HardwareKeyModifierKeys.Alternate) > 0) { flags |= UIKeyModifierFlags.Alternate; } if (((HardwareKeyModifierKeys)modifierKeys & HardwareKeyModifierKeys.CapsLock) > 0) { flags |= UIKeyModifierFlags.AlphaShift; } if (((HardwareKeyModifierKeys)modifierKeys & HardwareKeyModifierKeys.Control) > 0) { flags |= UIKeyModifierFlags.Control; } if (((HardwareKeyModifierKeys)modifierKeys & HardwareKeyModifierKeys.NumericPadKey) > 0) { flags |= UIKeyModifierFlags.NumericPad; } if (((HardwareKeyModifierKeys)modifierKeys & HardwareKeyModifierKeys.PlatformKey) > 0) { flags |= UIKeyModifierFlags.Command; } if (((HardwareKeyModifierKeys)modifierKeys & HardwareKeyModifierKeys.Shift) > 0) { flags |= UIKeyModifierFlags.Shift; } return(flags); }
static UIKeyCommand UIKeyCommandFrom(NSString nsInput, HardwareKeyModifierKeys modifier, string descriptiveText) { var flags = UIKeyModifierFlagsFrom(modifier); return(string.IsNullOrWhiteSpace(descriptiveText) ? UIKeyCommand.Create(nsInput, flags, _onKeyPressSelector) : UIKeyCommand.Create(nsInput, flags, _onKeyPressSelector, new NSString(descriptiveText))); }
/// <summary> /// Adds the hardware key listener to a View. /// </summary> /// <returns>The hardware key listener.</returns> /// <param name="view">View.</param> /// <param name="keyInput">Key input.</param> /// <param name="hardwareKeyModifierKeys">Hardware key modifier keys.</param> /// <param name="discoverableTitle">Discoverable title.</param> /// <param name="onPressed">On pressed.</param> public static HardwareKeyListener AddHardwareKeyListener(this View view, string keyInput, HardwareKeyModifierKeys hardwareKeyModifierKeys, string discoverableTitle, EventHandler <HardwareKeyEventArgs> onPressed = null) => AddHardwareKeyListener(view as VisualElement, keyInput, hardwareKeyModifierKeys, discoverableTitle, onPressed);
/// <summary> /// Initializes a new instance of the <see cref="T:Forms9Patch.HardwareKey"/> class. /// </summary> /// <param name="keyInput">KeyInput.</param> /// <param name="modifierKeys">Modifier keys.</param> /// <param name="discoverableTitle">Discoverable title.</param> public HardwareKey(string keyInput, HardwareKeyModifierKeys modifierKeys = HardwareKeyModifierKeys.None, string discoverableTitle = null) { KeyInput = keyInput; ModifierKeys = modifierKeys; DiscoverableTitle = discoverableTitle; }
/// <summary> /// Matches a hardware key listener and, if found, removes it from this ContentPage. /// </summary> /// <param name="page">Forms9Patch.HardwareKeyPage.</param> /// <param name="keyInput">Key Label.</param> /// <param name="hardwareKeyModifierKeys">Hardware key modifier keys.</param> public static void RemoveHardwareKeyListener(this PopupBase page, string keyInput, HardwareKeyModifierKeys hardwareKeyModifierKeys = HardwareKeyModifierKeys.None) => RemoveHardwareKeyListener(page as VisualElement, keyInput, hardwareKeyModifierKeys);
internal static HardwareKeyListener AddHardwareKeyListener(this VisualElement visualElement, string keyInput, HardwareKeyModifierKeys hardwareKeyModifierKeys = HardwareKeyModifierKeys.None, string discoverableTitle = null, EventHandler <HardwareKeyEventArgs> onPressed = null) { var hardwareKeyListener = new HardwareKeyListener(new HardwareKey(keyInput, hardwareKeyModifierKeys, discoverableTitle), onPressed); var listeners = visualElement.GetHardwareKeyListeners(); if (listeners.FirstOrDefault(l => l.HardwareKey == hardwareKeyListener.HardwareKey) is HardwareKeyListener redundantListener) { listeners.Remove(redundantListener); Console.WriteLine("Forms9Patch.HardwareKeyListener: Replacing [" + redundantListener + "] with [" + hardwareKeyListener + "]"); } listeners.Add(hardwareKeyListener); return(hardwareKeyListener); }
/// <summary> /// Matches a hardware key listener and, if found, removes it from this Xamarin.Forms.View. /// </summary> /// <param name="view">Xamarin.Forms.View.</param> /// <param name="keyInput">Key Label.</param> /// <param name="hardwareKeyModifierKeys">Hardware key modifier keys.</param> public static void RemoveHardwareKeyListener(this View view, string keyInput, HardwareKeyModifierKeys hardwareKeyModifierKeys = HardwareKeyModifierKeys.None) => RemoveHardwareKeyListener(view as VisualElement, keyInput, hardwareKeyModifierKeys);
internal static void RemoveHardwareKeyListener(this VisualElement visualElement, string keyInput, HardwareKeyModifierKeys hardwareKeyModifierKeys = HardwareKeyModifierKeys.None) { //foreach (var listener in visualElement.GetHardwareKeyListeners()) var listeners = visualElement.GetHardwareKeyListeners(); for (int i = 0; i < listeners.Count; i++) { var key = listeners[i].HardwareKey; if (key.KeyInput == keyInput && key.ModifierKeys == hardwareKeyModifierKeys) { listeners.RemoveAt(i); break; } } }
/// <summary> /// Adds a hardware key listener to a HardwareKeyPage. /// </summary> /// <returns>The hardware key listener.</returns> /// <param name="page">Page.</param> /// <param name="keyInput">Key input.</param> /// <param name="hardwareKeyModifierKeys">Hardware key modifier keys.</param> /// <param name="onPressed">On pressed.</param> public static HardwareKeyListener AddHardwareKeyListener(this PopupBase page, string keyInput, HardwareKeyModifierKeys hardwareKeyModifierKeys, EventHandler <HardwareKeyEventArgs> onPressed = null) => AddHardwareKeyListener(page as VisualElement, keyInput, hardwareKeyModifierKeys, null, onPressed);
internal static HardwareKeyListener AddHardwareKeyListener(this VisualElement visualElement, string keyInput, HardwareKeyModifierKeys hardwareKeyModifierKeys = HardwareKeyModifierKeys.None, string discoverableTitle = null, EventHandler <HardwareKeyEventArgs> onPressed = null) { var hardwareKeyListener = new HardwareKeyListener(new HardwareKey(keyInput, hardwareKeyModifierKeys, discoverableTitle), onPressed); var listeners = visualElement.GetHardwareKeyListeners(); listeners.Add(hardwareKeyListener); return(hardwareKeyListener); }
/// <summary> /// Adds a hardware key listener to a HardwareKeyPage. /// </summary> /// <returns>The hardware key listener.</returns> /// <param name="page">Page.</param> /// <param name="keyInput">Key input.</param> /// <param name="hardwareKeyModifierKeys">Hardware key modifier keys.</param> /// <param name="discoverableTitle">Discoverable title.</param> /// <param name="onPressed">On pressed.</param> public static HardwareKeyListener AddHardwareKeyListener(this Forms9Patch.HardwareKeyPage page, string keyInput, HardwareKeyModifierKeys hardwareKeyModifierKeys, string discoverableTitle, EventHandler <HardwareKeyEventArgs> onPressed = null) => AddHardwareKeyListener(page as VisualElement, keyInput, hardwareKeyModifierKeys, discoverableTitle, onPressed);