Exemplo n.º 1
0
        private void CoreDispatcher_AcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs e)
        {
            if ((e.EventType == CoreAcceleratorKeyEventType.SystemKeyDown ||
                 e.EventType == CoreAcceleratorKeyEventType.KeyDown))
            {
                var  coreWindow = Windows.UI.Xaml.Window.Current.CoreWindow;
                var  downState  = CoreVirtualKeyStates.Down;
                var  virtualKey = e.VirtualKey;
                bool winKey     = ((coreWindow.GetKeyState(VirtualKey.LeftWindows) & downState) == downState || (coreWindow.GetKeyState(VirtualKey.RightWindows) & downState) == downState);
                bool altKey     = (coreWindow.GetKeyState(VirtualKey.Menu) & downState) == downState;
                bool controlKey = (coreWindow.GetKeyState(VirtualKey.Control) & downState) == downState;
                bool shiftKey   = (coreWindow.GetKeyState(VirtualKey.Shift) & downState) == downState;

                // raise keydown actions
                var keyDown = new KeyboardEventArgs
                {
                    AltKey     = altKey,
                    Character  = ToChar(virtualKey, shiftKey),
                    ControlKey = controlKey,
                    EventArgs  = e,
                    ShiftKey   = shiftKey,
                    VirtualKey = virtualKey
                };

                try { KeyDown?.Invoke(keyDown); }
                catch { }

                // Only investigate further when Left, Right, or the dedicated Previous or Next keys
                // are pressed
                if (virtualKey == VirtualKey.Left ||
                    virtualKey == VirtualKey.Right ||
                    (int)virtualKey == 166 ||
                    (int)virtualKey == 167 ||
                    (int)virtualKey == 69)
                {
                    bool noModifiers = !altKey && !controlKey && !shiftKey;
                    bool onlyAlt     = altKey && !controlKey && !shiftKey;

                    if (((int)virtualKey == 166 && noModifiers) ||
                        (virtualKey == VirtualKey.Left && onlyAlt))
                    {
                        // When the previous key or Alt+Left are pressed navigate back
                        e.Handled = true;
                        RaiseGoBackGestured();
                    }
                    else if (virtualKey == VirtualKey.Back && winKey)
                    {
                        // When the next key or Win+Backspace are pressed navigate backward
                        e.Handled = true;
                        RaiseGoBackGestured();
                    }
                    else if (((int)virtualKey == 167 && noModifiers) || (virtualKey == VirtualKey.Right && onlyAlt))
                    {
                        // When the next key or Alt+Right are pressed navigate forward
                        e.Handled = true;
                        RaiseGoForwardGestured();
                    }
                    else if (((int)virtualKey == 69 && controlKey))
                    {
                        // when control-E
                        e.Handled = true;
                        RaiseControlEGestured();
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void CoreDispatcher_AcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs e)
        {
            if ((e.EventType == CoreAcceleratorKeyEventType.SystemKeyDown ||
                e.EventType == CoreAcceleratorKeyEventType.KeyDown))
            {
                var coreWindow = Windows.UI.Xaml.Window.Current.CoreWindow;
                var downState = CoreVirtualKeyStates.Down;
                var virtualKey = e.VirtualKey;
                bool winKey = ((coreWindow.GetKeyState(VirtualKey.LeftWindows) & downState) == downState || (coreWindow.GetKeyState(VirtualKey.RightWindows) & downState) == downState);
                bool altKey = (coreWindow.GetKeyState(VirtualKey.Menu) & downState) == downState;
                bool controlKey = (coreWindow.GetKeyState(VirtualKey.Control) & downState) == downState;
                bool shiftKey = (coreWindow.GetKeyState(VirtualKey.Shift) & downState) == downState;

                // raise keydown actions
                var keyDown = new KeyboardEventArgs
                {
                    AltKey = altKey,
                    Character = ToChar(virtualKey, shiftKey),
                    ControlKey = controlKey,
                    EventArgs = e,
                    ShiftKey = shiftKey,
                    VirtualKey = virtualKey
                };

                try { KeyDown?.Invoke(keyDown); }
                catch { }

                // Only investigate further when Left, Right, or the dedicated Previous or Next keys
                // are pressed
                if (virtualKey == VirtualKey.Left
                    || virtualKey == VirtualKey.Right
                    || (int)virtualKey == 166
                    || (int)virtualKey == 167
                    || (int)virtualKey == 69)
                {
                    bool noModifiers = !altKey && !controlKey && !shiftKey;
                    bool onlyAlt = altKey && !controlKey && !shiftKey;

                    if (((int)virtualKey == 166 && noModifiers)
                        || (virtualKey == VirtualKey.Left && onlyAlt))
                    {
                        // When the previous key or Alt+Left are pressed navigate back
                        e.Handled = true;
                        RaiseGoBackGestured();
                    }
                    else if (virtualKey == VirtualKey.Back && winKey)
                    {
                        // When the next key or Win+Backspace are pressed navigate backward
                        e.Handled = true;
                        RaiseGoBackGestured();
                    }
                    else if (((int)virtualKey == 167 && noModifiers) || (virtualKey == VirtualKey.Right && onlyAlt))
                    {
                        // When the next key or Alt+Right are pressed navigate forward
                        e.Handled = true;
                        RaiseGoForwardGestured();
                    }
                    else if (((int)virtualKey == 69 && controlKey))
                    {
                        // when control-E
                        e.Handled = true;
                        RaiseControlEGestured();
                    }
                }
            }
        }