Herald.Common.NavigationHelper.CoreDispatcher_AcceleratorKeyActivated C# (CSharp) Method

CoreDispatcher_AcceleratorKeyActivated() private method

当此页处于活动状态并占用整个窗口时,在每次 击键(包括系统键,如 Alt 组合键)时调用。 用于检测页之间的键盘 导航(即使在页本身没有焦点时)。
private CoreDispatcher_AcceleratorKeyActivated ( CoreDispatcher sender, AcceleratorKeyEventArgs e ) : void
sender Windows.UI.Core.CoreDispatcher 触发事件的实例。
e Windows.UI.Core.AcceleratorKeyEventArgs 描述导致事件的条件的事件数据。
return void
        private void CoreDispatcher_AcceleratorKeyActivated(CoreDispatcher sender,
            AcceleratorKeyEventArgs e)
        {
            var virtualKey = e.VirtualKey;

            // 仅当按向左、向右或专用上一页或下一页键时才进一步
            // 调查
            if ((e.EventType == CoreAcceleratorKeyEventType.SystemKeyDown ||
                e.EventType == CoreAcceleratorKeyEventType.KeyDown) &&
                (virtualKey == VirtualKey.Left || virtualKey == VirtualKey.Right ||
                (int)virtualKey == 166 || (int)virtualKey == 167))
            {
                var coreWindow = Window.Current.CoreWindow;
                var downState = CoreVirtualKeyStates.Down;
                bool menuKey = (coreWindow.GetKeyState(VirtualKey.Menu) & downState) == downState;
                bool controlKey = (coreWindow.GetKeyState(VirtualKey.Control) & downState) == downState;
                bool shiftKey = (coreWindow.GetKeyState(VirtualKey.Shift) & downState) == downState;
                bool noModifiers = !menuKey && !controlKey && !shiftKey;
                bool onlyAlt = menuKey && !controlKey && !shiftKey;

                if (((int)virtualKey == 166 && noModifiers) ||
                    (virtualKey == VirtualKey.Left && onlyAlt))
                {
                    // 在按上一页键或 Alt+向左键时向后导航
                    e.Handled = true;
                    this.GoBackCommand.Execute(null);
                }
                else if (((int)virtualKey == 167 && noModifiers) ||
                    (virtualKey == VirtualKey.Right && onlyAlt))
                {
                    // 在按下一页键或 Alt+向右键时向前导航
                    e.Handled = true;
                    this.GoForwardCommand.Execute(null);
                }
            }
        }