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);
        }
        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>
 /// Removes a hardware key listener from this Xamarin.Forms.View.
 /// </summary>
 /// <param name="page">Forms9Patch.HardwareKeyPage.</param>
 /// <param name="listener">Listener.</param>
 public static void RemoveHardwareKeyListener(this PopupBase page, HardwareKeyListener listener) => RemoveHardwareKeyListener(page as VisualElement, listener);
 /// <summary>
 /// Removes a hardware key listener from this ContentPage.
 /// </summary>
 /// <param name="view">View.</param>
 /// <param name="listener">Listener.</param>
 public static void RemoveHardwareKeyListener(this View view, HardwareKeyListener listener) => RemoveHardwareKeyListener(view as VisualElement, listener);
        internal static void RemoveHardwareKeyListener(this VisualElement visualElement, HardwareKeyListener listener)
        {
            var listeners = visualElement.GetHardwareKeyListeners();

            if (listeners.Contains(listener))
            {
                listeners.Remove(listener);
            }
        }
 /// <summary>
 /// Adds a hardware key listener to this ContentPage.
 /// </summary>
 /// <returns>The hardware key listener.</returns>
 /// <param name="page">Forms9Patch.HardwareKeyPage.</param>
 /// <param name="hardwareKeyListener">Hardware key listener.</param>
 public static HardwareKeyListener AddHardwareKeyListener(this PopupBase page, HardwareKeyListener hardwareKeyListener) => AddHardwareKeyListener(page as VisualElement, hardwareKeyListener);
 /// <summary>
 /// Adds a hardware key listener to this Xamarin.Forms.View.
 /// </summary>
 /// <returns>The hardware key listener.</returns>
 /// <param name="view">Xamarin.Forms.View.</param>
 /// <param name="hardwareKeyListener">Hardware key listener.</param>
 public static HardwareKeyListener AddHardwareKeyListener(this View view, HardwareKeyListener hardwareKeyListener) => AddHardwareKeyListener(view as VisualElement, hardwareKeyListener);
        internal static HardwareKeyListener AddHardwareKeyListener(this VisualElement visualElement, HardwareKeyListener hardwareKeyListener)
        {
            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>
 /// Removes a hardware key listener from this Xamarin.Forms.View.
 /// </summary>
 /// <param name="page">Forms9Patch.HardwareKeyPage.</param>
 /// <param name="listener">Listener.</param>
 public static void RemoveHardwareKeyListener(this Forms9Patch.HardwareKeyPage page, HardwareKeyListener listener) => RemoveHardwareKeyListener(page as VisualElement, listener);
 /// <summary>
 /// Adds a hardware key listener to this ContentPage.
 /// </summary>
 /// <returns>The hardware key listener.</returns>
 /// <param name="page">Forms9Patch.HardwareKeyPage.</param>
 /// <param name="hardwareKeyListener">Hardware key listener.</param>
 public static HardwareKeyListener AddHardwareKeyListener(this Forms9Patch.HardwareKeyPage page, HardwareKeyListener hardwareKeyListener) => AddHardwareKeyListener(page as VisualElement, hardwareKeyListener);
 internal static HardwareKeyListener AddHardwareKeyListener(this VisualElement visualElement, HardwareKeyListener hardwareKeyListener)
 {
     visualElement.GetHardwareKeyListeners().Add(hardwareKeyListener);
     return(hardwareKeyListener);
 }