示例#1
0
文件: Desktop.cs 项目: janfokke/Myra
        public static void OnKeyDown(Keys key)
        {
            KeyDown.Invoke(key);

            if (IsMenuBarActive)
            {
                MenuBar.OnKeyDown(key);
            }
            else
            {
                // Small workaround: if key is escape  active widget is window
                // Send it there
                var topWidget = GetTopWidget();
                var asWindow  = topWidget as Window;
                if (asWindow != null)
                {
                    if (key == Keys.Escape)
                    {
                        asWindow.OnKeyDown(key);
                    }

                    var asDialog = asWindow as Dialog;
                    if (asDialog != null && key == Keys.Enter)
                    {
                        // Dialog also always receives Enter (Ok)
                        asWindow.OnKeyDown(key);
                    }
                }

                if (_focusedKeyboardWidget != null && _focusedKeyboardWidget.Active)
                {
                    _focusedKeyboardWidget.OnKeyDown(key);

#if XENKO
                    var ch = key.ToChar(_downKeys.Contains(Keys.LeftShift) ||
                                        _downKeys.Contains(Keys.RightShift));
                    if (ch != null)
                    {
                        _focusedKeyboardWidget.OnChar(ch.Value);
                    }
#endif
                }
            }

            if (key == Keys.Escape && ContextMenu != null)
            {
                HideContextMenu();
            }

#if MONOGAME
            if (!HasExternalTextInput && !IsControlDown && !IsAltDown)
            {
                var c = key.ToChar(IsShiftDown);
                if (c != null)
                {
                    OnChar(c.Value);
                }
            }
#endif
        }
示例#2
0
        public void OnKeyDown(Keys key)
        {
            KeyDown.Invoke(this, key);

            if (MenuBar != null && MyraEnvironment.ShowUnderscores)
            {
                MenuBar.OnKeyDown(key);
            }
            else
            {
                // Small workaround: if key is escape  active widget is window
                // Send it there
                var asWindow = GetTopWidget(false) as Window;
                if (asWindow != null && key == Keys.Escape && _focusedKeyboardWidget != asWindow)
                {
                    asWindow.OnKeyDown(key);
                }

                if (_focusedKeyboardWidget != null)
                {
                    _focusedKeyboardWidget.OnKeyDown(key);

#if XENKO
                    var ch = key.ToChar(_downKeys.Contains(Keys.LeftShift) ||
                                        _downKeys.Contains(Keys.RightShift));
                    if (ch != null)
                    {
                        _focusedKeyboardWidget.OnChar(ch.Value);
                    }
#endif
                }
            }

            if (key == Keys.Escape && ContextMenu != null)
            {
                HideContextMenu();
            }

#if MONOGAME
            if (!HasExternalTextInput && !IsControlDown && !IsAltDown)
            {
                var c = key.ToChar(IsShiftDown);
                if (c != null)
                {
                    OnChar(c.Value);
                }
            }
#endif
        }
示例#3
0
        public void OnKeyDown(Keys key)
        {
            var ev = KeyDown;

            if (ev != null)
            {
                ev(this, new GenericEventArgs <Keys>(key));
            }

            if (MenuBar != null && MyraEnvironment.ShowUnderscores)
            {
                MenuBar.OnKeyDown(key);
            }
            else
            {
                // Small workaround: if key is escape  active widget is window
                // Send it there
                var asWindow = GetActiveWidget() as Window;
                if (asWindow != null && key == Keys.Escape && _focusedKeyboardWidget != asWindow)
                {
                    asWindow.OnKeyDown(key);
                }

                if (_focusedKeyboardWidget != null)
                {
                    _focusedKeyboardWidget.OnKeyDown(key);

#if XENKO
                    var ch = key.ToChar(_downKeys.Contains(Keys.LeftShift) ||
                                        _downKeys.Contains(Keys.RightShift));
                    if (ch != null)
                    {
                        _focusedKeyboardWidget.OnChar(ch.Value);
                    }
#endif
                }
            }

            if (key == Keys.Escape && ContextMenu != null)
            {
                HideContextMenu();
            }
        }
示例#4
0
        public void OnKeyDown(Keys key)
        {
            KeyDown.Invoke(key);

            if (IsMenuBarActive)
            {
                MenuBar.OnKeyDown(key);
            }
            else
            {
                if (_focusedKeyboardWidget != null && _focusedKeyboardWidget.Active)
                {
                    _focusedKeyboardWidget.OnKeyDown(key);

#if STRIDE
                    var ch = key.ToChar(_downKeys.Contains(Keys.LeftShift) ||
                                        _downKeys.Contains(Keys.RightShift));
                    if (ch != null)
                    {
                        _focusedKeyboardWidget.OnChar(ch.Value);
                    }
#elif MONOGAME
                    if (!HasExternalTextInput && !IsControlDown && !IsAltDown)
                    {
                        var c = key.ToChar(IsShiftDown);
                        if (c != null)
                        {
                            OnChar(c.Value);
                        }
                    }
#endif
                }
            }

            if (key == Keys.Escape && ContextMenu != null)
            {
                HideContextMenu();
            }
        }