private void OnAcceleratorKeyActivated( CoreDispatcher sender, AcceleratorKeyEventArgs args ) { Contract.Requires( args != null ); // only investigate further when Left, Right, or the dedicated Previous or Next keys are pressed var virtualKey = args.VirtualKey; var shouldHandle = ( args.EventType == SystemKeyDown || args.EventType == KeyDown ) && ( virtualKey == Left || virtualKey == Right || (int) virtualKey == 166 || (int) virtualKey == 167 ); if ( !shouldHandle ) return; var window = Window.Current.CoreWindow; var down = CoreVirtualKeyStates.Down; var menuKey = ( window.GetKeyState( Menu ) & down ) == down; var controlKey = ( window.GetKeyState( Control ) & down ) == down; var shiftKey = ( window.GetKeyState( Shift ) & down ) == down; var noModifiers = !menuKey && !controlKey && !shiftKey; var onlyAlt = menuKey && !controlKey && !shiftKey; var frame = AssociatedObject.Frame; if ( ( ( (int) virtualKey == 166 && noModifiers ) || ( virtualKey == Left && onlyAlt ) ) && frame.CanGoBack ) { // navigate back when the previous key or Alt+Left are pressed frame.GoBack(); args.Handled = true; } else if ( ( ( (int) virtualKey == 167 && noModifiers ) || ( virtualKey == Right && onlyAlt ) ) && frame.CanGoBack ) { // navigate forward when the next key or Alt+Right are pressed frame.GoForward(); args.Handled = true; } }
/// <summary> /// 이 페이지가 활성화되고 전체 창 크기로 표시된 경우 Alt 키 조합 등 /// 시스템 키를 포함한 모든 키 입력에서 호출됩니다. 페이지에 포커스가 없으면 /// 페이지 간 키보드 탐색을 검색하는 데 사용됩니다. /// </summary> /// <param name="sender">이벤트를 트리거한 인스턴스입니다.</param> /// <param name="e">이벤트의 발생 조건을 설명하는 이벤트 데이터입니다.</param> 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); } } }
/// <summary> /// 当此页处于活动状态并占用整个窗口时,在每次 /// 击键(包括系统键,如 Alt 组合键)时调用。 用于检测页之间的键盘 /// 导航(即使在页本身没有焦点时)。 /// </summary> /// <param name="sender">触发事件的实例。</param> /// <param name="e">描述导致事件的条件的事件数据。</param> 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); } } }
/// <summary> /// Вызывается при каждом нажатии клавиши, включая системные клавиши, такие как клавиша ALT, если /// данная страница активна и занимает все окно. Используется для обнаружения навигации с помощью клавиатуры /// между страницами, даже если сама страница не имеет фокуса. /// </summary> /// <param name="sender">Экземпляр, инициировавший событие.</param> /// <param name="e">Данные события, описывающие условия, которые привели к возникновению события.</param> 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); } } }
/// <summary> /// Se invoca en cada pulsación de tecla, incluidas las teclas del sistema como combinaciones de teclas Alt, cuando /// esta página está activa y ocupa toda la ventana. Se usa para detectar la navegación con el teclado /// entre páginas incluso cuando la página no tiene el foco. /// </summary> /// <param name="sender">Instancia que desencadena el evento.</param> /// <param name="e">Datos de evento que describen las condiciones que dan lugar al evento.</param> private void CoreDispatcher_AcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs e) { var virtualKey = e.VirtualKey; // Investigar más solo cuando se presionan las teclas Izquierda, Derecha o las teclas // dedicadas Repág o Avpág 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)) { // Cuando se presionan las teclas Repág o Alt+Izquierda, navegar hacia atrás e.Handled = true; this.GoBackCommand.Execute(null); } else if (((int)virtualKey == 167 && noModifiers) || (virtualKey == VirtualKey.Right && onlyAlt)) { // Cuando se presionan las teclas Avpág o Alt+Derecha, navegar hacia delante e.Handled = true; this.GoForwardCommand.Execute(null); } } }
/// <summary> /// Invoqué à chaque séquence de touches, notamment les touches système comme les combinaisons utilisant la touche Alt, lorsque /// cette page est active et occupe la totalité de la fenêtre. Utilisé pour détecter la navigation à l'aide du clavier /// entre les pages, même lorsque la page elle-même n'a pas le focus. /// </summary> /// <param name="sender">Instance qui a déclenché l'événement.</param> /// <param name="e">Données d'événement décrivant les conditions ayant déclenché l'événement.</param> private void CoreDispatcher_AcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs e) { var virtualKey = e.VirtualKey; // Approfondit les recherches uniquement lorsque les touches Gauche, Droite ou les touches Précédent et Suivant dédiées // sont actionnées 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)) { // Lorsque la touche Précédent ou les touches Alt+Gauche sont actionnées, navigue vers l'arrière e.Handled = true; this.GoBackCommand.Execute(null); } else if (((int)virtualKey == 167 && noModifiers) || (virtualKey == VirtualKey.Right && onlyAlt)) { // Lorsque la touche Suivant ou les touches Alt+Droite sont actionnées, navigue vers l'avant e.Handled = true; this.GoForwardCommand.Execute(null); } } }
/// <summary> /// Richiamato per ciascuna sequenza di tasti, compresi i tasti di sistema quali combinazioni con il tasto ALT, quando /// questa pagina è attiva e occupa l'intera finestra. Utilizzato per il rilevamento della navigazione da tastiera /// tra pagine, anche quando la pagina stessa no dispone dello stato attivo. /// </summary> /// <param name="sender">Istanza che ha generato l'evento.</param> /// <param name="e">Dati evento che descrivono le condizioni che hanno determinato l'evento.</param> private void CoreDispatcher_AcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs e) { var virtualKey = e.VirtualKey; // Esegui ulteriori controlli solo se vengono premuti i tasti Freccia SINISTRA, Freccia DESTRA o i tasti dedicati Precedente // o successivo 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)) { // Quando viene premuto il tasto Precedente o ALT+Freccia SINISTRA, torna indietro e.Handled = true; this.GoBackCommand.Execute(null); } else if (((int)virtualKey == 167 && noModifiers) || (virtualKey == VirtualKey.Right && onlyAlt)) { // Quando viene premuto il tasto Successivo o ALT+Freccia DESTRA, vai avanti e.Handled = true; this.GoForwardCommand.Execute(null); } } }
private void CoreDispatcher_AcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs e) { var virtualKey = e.VirtualKey; // Only investigate further when Left, Right, or the dedicated Previous or Next keys // are pressed 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)) { // When the previous key or Alt+Left are pressed navigate back e.Handled = true; this.GoBackCommand.Execute(null); } else if (((int)virtualKey == 167 && noModifiers) || (virtualKey == VirtualKey.Right && onlyAlt)) { // When the next key or Alt+Right are pressed navigate forward e.Handled = true; this.GoForwardCommand.Execute(null); } } }
/// <summary> /// このページがアクティブで、ウィンドウ全体を使用する場合、Alt キーの組み合わせなどのシステム キーを含む、 /// キーボード操作で呼び出されます。ページがフォーカスされていないときでも、 /// ページ間のキーボード ナビゲーションの検出に使用されます。 /// </summary> /// <param name="sender">イベントをトリガーしたインスタンス。</param> /// <param name="args">イベントが発生する条件を説明するイベント データ。</param> private void CoreDispatcher_AcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs args) { var virtualKey = args.VirtualKey; // 左方向キーや右方向キー、または専用に設定した前に戻るキーや次に進むキーを押した場合のみ、 // 詳細を調査します if ((args.EventType == CoreAcceleratorKeyEventType.SystemKeyDown || args.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 キーを押しながら左方向キーを押すと前に戻ります args.Handled = true; this.GoBack(this, new RoutedEventArgs()); } else if (((int)virtualKey == 167 && noModifiers) || (virtualKey == VirtualKey.Right && onlyAlt)) { // 次に進むキーまたは Alt キーを押しながら右方向キーを押すと次に進みます args.Handled = true; this.GoForward(this, new RoutedEventArgs()); } } }
private static void OnAcceleratorKeyActivated(CoreDispatcher dispatcher, AcceleratorKeyEventArgs args) { if (args.KeyStatus.IsKeyReleased) { var key = args.VirtualKey; bool altPressed = args.KeyStatus.IsMenuKeyDown; // If the Alt/Menu key is not pressed then we don't care about the key anymore if (!altPressed) { return; } bool controlKeyPressed = (Window.Current.CoreWindow.GetKeyState(Windows.System.VirtualKey.Control) & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down; // Ctrl is pressed in addition to alt, this means Alt Gr is intended. do not navigate. if (controlKeyPressed) { return; } bool shiftKeyPressed = (Window.Current.CoreWindow.GetKeyState(Windows.System.VirtualKey.Shift) & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down; NavigateModeByShortcut(controlKeyPressed, shiftKeyPressed, altPressed, key, null); } }
private void Dispatcher_AcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs args) { App.HandleKeyPress(args.VirtualKey, args.KeyStatus.IsKeyReleased); }
private static void Dispatcher_AcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs args) { if (!_isEnterPressed) { return; } if (_command == null) { return; } if (args.VirtualKey != VirtualKey.Enter) { return; } if (args.EventType == CoreAcceleratorKeyEventType.KeyDown) { args.Handled = true; _command?.Execute(null); } }
private void Dispatcher_AcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs args) { focusButton.Focus(FocusState.Programmatic); var key = args.VirtualKey.ToString(); var shift = Window.Current.CoreWindow.GetKeyState(VirtualKey.Shift); if (!args.EventType.ToString().Contains("Down")) { return; } if (shift.HasFlag(CoreVirtualKeyStates.Down) && args.VirtualKey == VirtualKey.Number7) { key = "Divide"; } switch (key) { case "Add": case "187": Calculate("+"); return; case "Subtract": case "189": Calculate("-"); return; case "Multiply": case "191": Calculate("x"); return; case "Divide": Calculate("/"); return; case "Enter": Calculate("="); return; case "Back": case "Delete": Erase(); return; case "C": TempConversion("C"); return; case "F": TempConversion("F"); return; default: break; } for (int i = 0; i < 10; i++) { if (key == $"Number{i}" || key == $"NumberPad{i}") { if (textBlock.Text.Length > 15) { return; } if (newLine) { textBlock.Text = ""; newLine = false; } textBlock.Text = textBlock.Text == "0" ? "" : textBlock.Text; textBlock.Text += i; } } }
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(); } } } }
private static void CoreDispatcher_AcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs e) { var downState = CoreVirtualKeyStates.Down; CoreWindow coreWindow = Window.Current.CoreWindow; 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; if (noModifiers && e.EventType == CoreAcceleratorKeyEventType.KeyDown && (e.VirtualKey == VirtualKey.Enter || e.VirtualKey == VirtualKey.Escape)) { var frame = Window.Current.Content as Frame; if (frame == null) { return; } var currentPage = frame.Content as Page; if (currentPage == null) { return; } if (e.VirtualKey == VirtualKey.Enter) { // Quick check to avoid TextBox with ENTER support var tb = FocusManager.GetFocusedElement() as TextBox; if (tb != null && tb.AcceptsReturn) { return; } var defaultButton = currentPage.GetValue(DefaultButtonProperty) as Button; if (defaultButton != null && defaultButton.IsEnabled) { var peer = new ButtonAutomationPeer(defaultButton); var invokeProv = peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider; if (invokeProv != null) { invokeProv.Invoke(); } } } else { var cancelButton = currentPage.GetValue(CancelButtonProperty) as Button; if (cancelButton != null && cancelButton.IsEnabled) { var peer = new ButtonAutomationPeer(cancelButton); var invokeProv = peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider; if (invokeProv != null) { invokeProv.Invoke(); } } } } }
public async void AccelertorKeyActivedHandle(CoreDispatcher sender, AcceleratorKeyEventArgs args) { if (args.EventType.ToString().Contains("Down")) { var esc = Window.Current.CoreWindow.GetKeyState(VirtualKey.Escape); var space = Window.Current.CoreWindow.GetKeyState(VirtualKey.Space); var f11 = Window.Current.CoreWindow.GetKeyState(VirtualKey.F11); var f10 = Window.Current.CoreWindow.GetKeyState(VirtualKey.F10); var f2 = Window.Current.CoreWindow.GetKeyState(VirtualKey.F2); var left = Window.Current.CoreWindow.GetKeyState(VirtualKey.Left); var right = Window.Current.CoreWindow.GetKeyState(VirtualKey.Right); var up = Window.Current.CoreWindow.GetKeyState(VirtualKey.Up); var down = Window.Current.CoreWindow.GetKeyState(VirtualKey.Down); var shift = Window.Current.CoreWindow.GetKeyState(VirtualKey.Shift); var player = CurrentVideoPlayer; if (esc.HasFlag(CoreVirtualKeyStates.Down)) { if (App.AppViewModel._dynamicDetailPopup != null && App.AppViewModel._dynamicDetailPopup._popup.IsOpen) { App.AppViewModel._dynamicDetailPopup.HidePopup(); return; } if (player != null) { if (player.MTC.IsFullWindow) { args.Handled = true; player.MTC.IsFullWindow = false; } else if (player.MTC.IsCinema) { args.Handled = true; player.MTC.IsCinema = false; } player.Focus(FocusState.Programmatic); } } else if (space.HasFlag(CoreVirtualKeyStates.Down)) { if (player != null && player.IsFocus && (player.MTC.IsFullWindow || player.MTC.IsCinema)) { args.Handled = true; player.MTC.IsPlaying = !player.MTC.IsPlaying; player.Focus(FocusState.Programmatic); } } else if (f11.HasFlag(CoreVirtualKeyStates.Down)) { if (player != null && player.IsFocus) { args.Handled = true; player.MTC.IsFullWindow = !player.MTC.IsFullWindow; } } else if (f10.HasFlag(CoreVirtualKeyStates.Down)) { if (player != null && player.IsFocus) { args.Handled = true; player.MTC.IsCompactOverlay = !player.MTC.IsCompactOverlay; } } else if (f2.HasFlag(CoreVirtualKeyStates.Down)) { if (player != null && player.IsFocus) { args.Handled = true; await player.ChangeDanmakuStatus(); } } else if (left.HasFlag(CoreVirtualKeyStates.Down)) { if (player != null && player.IsFocus) { args.Handled = true; player.SkipRewind(); } } else if (right.HasFlag(CoreVirtualKeyStates.Down)) { if (player != null && player.IsFocus) { args.Handled = true; player.SkipForward(); } } else if (up.HasFlag(CoreVirtualKeyStates.Down)) { if (player != null && player.IsFocus) { args.Handled = true; player.UpVolume(); } } else if (down.HasFlag(CoreVirtualKeyStates.Down)) { if (player != null && player.IsFocus) { args.Handled = true; player.DownVolume(); } } else if (shift.HasFlag(CoreVirtualKeyStates.Down)) { if (args.VirtualKey == VirtualKey.S) { //截图 if (player != null && player.IsFocus) { await player.ScreenShot(); } } } } }
private static void OnAcceleratorKeyActivated(ReactNativeHost host, CoreDispatcher sender, AcceleratorKeyEventArgs e) { if (host.HasInstance) { var reactInstanceManager = host.ReactInstanceManager; if (reactInstanceManager.DevSupportManager.IsEnabled) { if (e.VirtualKey == VirtualKey.Shift) { s_isShiftKeyDown = e.EventType == CoreAcceleratorKeyEventType.KeyDown; } else if (e.VirtualKey == VirtualKey.Control) { s_isControlKeyDown = e.EventType == CoreAcceleratorKeyEventType.KeyDown; } else if (e.EventType == CoreAcceleratorKeyEventType.KeyDown && s_isShiftKeyDown && e.VirtualKey == VirtualKey.F10) { reactInstanceManager.DevSupportManager.ShowDevOptionsDialog(); } else if (e.EventType == CoreAcceleratorKeyEventType.KeyUp && s_isControlKeyDown && e.VirtualKey == VirtualKey.R) { reactInstanceManager.DevSupportManager.HandleReloadJavaScript(); } } } }
/// <summary>Called when a key up event has occured (not supported on WP). </summary> /// <param name="args">The event arguments. </param> protected internal virtual void OnKeyUp(AcceleratorKeyEventArgs args) { // Must be empty }
private static async void OnAcceleratorKeyActivated(ReactNativeHost host, CoreDispatcher sender, AcceleratorKeyEventArgs e) { if (host.HasInstance) { var reactInstanceManager = host.ReactInstanceManager; if (reactInstanceManager.DevSupportManager.IsEnabled) { if (e.VirtualKey == VirtualKey.Shift) { s_isShiftKeyDown = e.EventType == CoreAcceleratorKeyEventType.KeyDown; } else if (e.VirtualKey == VirtualKey.Control) { s_isControlKeyDown = e.EventType == CoreAcceleratorKeyEventType.KeyDown; } else if ((s_isShiftKeyDown && e.VirtualKey == VirtualKey.F10) || (e.EventType == CoreAcceleratorKeyEventType.KeyDown && e.VirtualKey == VirtualKey.Menu)) { reactInstanceManager.DevSupportManager.ShowDevOptionsDialog(); } else if (e.EventType == CoreAcceleratorKeyEventType.KeyUp && s_isControlKeyDown && e.VirtualKey == VirtualKey.R) { await reactInstanceManager.DevSupportManager.CreateReactContextFromPackagerAsync(CancellationToken.None).ConfigureAwait(false); } } } }
private async void Dispatcher_AcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs args) { await HandleKey(sender, args); }
/// <summary> /// Detect an accelerator key /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void DispatcherOnAcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs e) { Debug.WriteLine("Key:{0}, EventType:{1}, IsMenuKeyDown:{2}", e.VirtualKey, e.EventType, e.KeyStatus.IsMenuKeyDown); if (e.EventType == CoreAcceleratorKeyEventType.KeyDown || e.EventType == CoreAcceleratorKeyEventType.SystemKeyDown) { if (!ActiveKeys.Contains(e.VirtualKey)) { ActiveKeys.Add(e.VirtualKey); } } else if (e.EventType == CoreAcceleratorKeyEventType.KeyUp || e.EventType == CoreAcceleratorKeyEventType.SystemKeyUp) { if (ActiveKeys.Contains(e.VirtualKey)) { CheckForActiveKey(); ActiveKeys.Remove(e.VirtualKey); } } }
protected override void CoreDispatcher_AcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs args) { if (args.EventType != CoreAcceleratorKeyEventType.KeyDown && args.EventType != CoreAcceleratorKeyEventType.SystemKeyDown) { return; } switch (args.VirtualKey) { case VirtualKey.Space: if (xMediaPlayer.CurrentState == MediaElementState.Playing) { xPlayerControler_MediaElementStatusChanged(this, MediaElementState.Paused); } else if (xMediaPlayer.CurrentState == MediaElementState.Paused) { xPlayerControler_MediaElementStatusChanged(this, MediaElementState.Playing); } break; case VirtualKey.Left: if (!_playFactory.SupportSeek) { return; } var leftposition = xMediaPlayer.Position.Add(TimeSpan.FromSeconds(-5)); if (leftposition.TotalSeconds > 0) { _timer.Stop(); xPlayerControler.SetPlayerPostions(xMediaPlayer.NaturalDuration, leftposition, GetPlayDownloadPosition()); xMediaPlayer.Position = leftposition; _timer.Start(); } break; case VirtualKey.Right: if (!_playFactory.SupportSeek) { return; } var rigthposition = xMediaPlayer.Position.Add(TimeSpan.FromSeconds(5)); if (rigthposition.TotalSeconds > 0) { _timer.Stop(); xPlayerControler.SetPlayerPostions(xMediaPlayer.NaturalDuration, rigthposition, GetPlayDownloadPosition()); xMediaPlayer.Position = rigthposition; _timer.Start(); } break; case VirtualKey.Up: if (xMediaPlayer.IsMuted) { xMediaPlayer.IsMuted = false; } if (xMediaPlayer.Volume <= 1) { xPlayerControler.SetVolumeValue(xMediaPlayer.Volume += .1); } break; case VirtualKey.Down: if (xMediaPlayer.Volume > 0) { xPlayerControler.SetVolumeValue(xMediaPlayer.Volume -= .1); } else { xMediaPlayer.IsMuted = true; } break; } base.CoreDispatcher_AcceleratorKeyActivated(sender, args); }
private void OnAcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs args) { _page.OnKeyActivated(args); if (args.KeyStatus.IsKeyReleased) { _page.OnKeyUp(args); } if (args.Handled) { return; } var virtualKey = args.VirtualKey; if (args.EventType == CoreAcceleratorKeyEventType.KeyDown || args.EventType == CoreAcceleratorKeyEventType.SystemKeyDown) { var isLeftOrRightKey = _page.UseAltLeftOrRightToNavigate && ( virtualKey == VirtualKey.Left || virtualKey == VirtualKey.Right || (int)virtualKey == 166 || (int)virtualKey == 167); var isBackKey = _page.UseBackKeyToNavigate && virtualKey == VirtualKey.Back; if (isLeftOrRightKey || isBackKey) { if (PopupHelper.IsPopupVisible) { return; } var element = FocusManager.GetFocusedElement(); if (element is FrameworkElement && PopupHelper.IsInPopup((FrameworkElement)element)) { return; } if (isBackKey) { if (!(element is TextBox) && !(element is PasswordBox) && (_page.UseBackKeyToNavigateInWebView || !(element is WebView)) && _page.Frame.CanGoBack) { args.Handled = true; TryGoBackAsync(); } } else { var altKey = Keyboard.IsAltKeyDown; var controlKey = Keyboard.IsControlKeyDown; var shiftKey = Keyboard.IsShiftKeyDown; var noModifiers = !altKey && !controlKey && !shiftKey; var onlyAlt = altKey && !controlKey && !shiftKey; if (((int)virtualKey == 166 && noModifiers) || (virtualKey == VirtualKey.Left && onlyAlt)) { args.Handled = true; TryGoBackAsync(); } else if (((int)virtualKey == 167 && noModifiers) || (virtualKey == VirtualKey.Right && onlyAlt)) { args.Handled = true; TryGoForwardAsync(); } } } } }
private void Dispatcher_AcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs args) { if (Items.Count == 0) { return; } _lastFocusElement = FocusManager.GetFocusedElement() as Control; if (args.VirtualKey == VirtualKey.Menu) { if (!IsOpened) { if (_isLostFocus) { ((MenuItem)Items[0]).Focus(FocusState.Programmatic); if (!(_lastFocusElement is MenuItem)) { _lastFocusElementBeforeMenu = _lastFocusElement; } if (AllowTooltip) { ShowMenuItemsToolTips(); } else { UnderlineMenuItems(); } if (args.KeyStatus.IsKeyReleased) { _isLostFocus = false; } } else if (!_isLostFocus && args.KeyStatus.IsKeyReleased) { if (AllowTooltip) { HideMenuItemsTooltips(); } else { RemoveUnderlineMenuItems(); } _lastFocusElementBeforeMenu?.Focus(FocusState.Keyboard); } } } else if ((args.KeyStatus.IsMenuKeyDown || !_isLostFocus) && args.KeyStatus.IsKeyReleased) { var gestureKey = MapInputToGestureKey(args.VirtualKey, !_isLostFocus); if (gestureKey == null) { return; } if (MenuItemInputGestureCache.ContainsKey(gestureKey)) { var cachedMenuItem = MenuItemInputGestureCache[gestureKey]; if (cachedMenuItem is MenuItem) { var menuItem = (MenuItem)cachedMenuItem; menuItem.ShowMenu(); menuItem.Focus(FocusState.Keyboard); } } } }
private void Dispatcher_AcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs args) { if (Items.Count == 0) { return; } if (ControlHelpers.IsXamlRootAvailable && XamlRoot != null) { _lastFocusElement = FocusManager.GetFocusedElement(XamlRoot) as Control; } else { _lastFocusElement = FocusManager.GetFocusedElement() as Control; } if (args.KeyStatus.ScanCode != AltScanCode) { _onlyAltCharacterPressed = false; } if (args.VirtualKey == VirtualKey.Menu) { if (!IsOpened) { if (_isLostFocus) { if (_onlyAltCharacterPressed && args.KeyStatus.IsKeyReleased) { ((MenuItem)Items[0]).Focus(FocusState.Programmatic); if (!(_lastFocusElement is MenuItem)) { _lastFocusElementBeforeMenu = _lastFocusElement; } } if (AllowTooltip) { ShowMenuItemsToolTips(); } else { UnderlineMenuItems(); } if (args.KeyStatus.IsKeyReleased) { _isLostFocus = false; } } else if (args.KeyStatus.IsKeyReleased) { HideToolTip(); _lastFocusElementBeforeMenu?.Focus(FocusState.Keyboard); } } } else if ((args.KeyStatus.IsMenuKeyDown || !_isLostFocus) && args.KeyStatus.IsKeyReleased) { var gestureKey = MapInputToGestureKey(args.VirtualKey, !_isLostFocus); if (gestureKey == null) { return; } if (MenuItemInputGestureCache.ContainsKey(gestureKey)) { var cachedMenuItem = MenuItemInputGestureCache[gestureKey]; if (cachedMenuItem is MenuItem) { var menuItem = (MenuItem)cachedMenuItem; menuItem.ShowMenu(); menuItem.Focus(FocusState.Keyboard); } } } if (args.KeyStatus.IsKeyReleased && args.EventType == CoreAcceleratorKeyEventType.KeyUp) { _onlyAltCharacterPressed = true; _isLostFocus = true; HideToolTip(); } }
private async void Dispatcher_AcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs e) { if (!xpoWebView.IsWebAppLoaded) { return; } if (e.EventType == CoreAcceleratorKeyEventType.KeyDown || e.EventType == CoreAcceleratorKeyEventType.SystemKeyDown) { // We won't process the event if the currently focused element is WebView, // as the web app can handle keyboard shortcuts itself. if (FocusManager.GetFocusedElement().GetType() == typeof(WebView)) { return; } var shiftState = CoreWindow.GetForCurrentThread().GetKeyState(VirtualKey.Shift); var shiftPressed = (shiftState & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down; var ctrlState = CoreWindow.GetForCurrentThread().GetKeyState(VirtualKey.Control); var ctrlPressed = (ctrlState & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down; var altState = CoreWindow.GetForCurrentThread().GetKeyState(VirtualKey.Menu); var altPressed = (altState & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down; logger.Info(e.VirtualKey); var isHandled = await KeyboardShortcutHelper.KeyDown(e.VirtualKey, shiftPressed, ctrlPressed, altPressed, xpoWebView.Controller, nowPlaying); if (isHandled == KeyboardShortcutHelper.KeyDownProcessResult.AskJs) { logger.Info("Sending it to js..."); int charCode = (int)e.VirtualKey; var handledByJs = await xpoWebView.Controller.OnKeyDown(charCode, shiftPressed, ctrlPressed, altPressed); if (handledByJs) { if (nowPlaying.IsOpen) { if (nowPlaying.ViewMode == NowPlayingView.NowPlayingViewMode.CompactOverlay) { CloseCompactOverlay(); } else { CloseNowPlaying(); } } } } else if (isHandled == KeyboardShortcutHelper.KeyDownProcessResult.GoBack) { if (nowPlaying.IsOpen) { if (nowPlaying.ViewMode == NowPlayingView.NowPlayingViewMode.CompactOverlay) { CloseCompactOverlay(); } else if (ApplicationView.GetForCurrentView().IsFullScreenMode) { nowPlaying.ToggleFullscreen(); } else { CloseNowPlaying(); } } } } }
private void Dispatcher_AcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs args) { var viewport = GetViewport(); if (viewport == null) { return; } if (!GetEKeyByVirtualKey(args.VirtualKey, out EKeys eKey)) { return; } if (args.EventType == CoreAcceleratorKeyEventType.KeyDown || args.EventType == CoreAcceleratorKeyEventType.SystemKeyDown) { bool handled = false; var keyEvent = new KeyEvent(eKey); viewport.PerformKeyDown(keyEvent, ref handled); if (keyEvent.SuppressKeyPress) { args.Handled = true; } if (!handled && EngineApp.InitSettings.AllowChangeScreenVideoMode) { //support Alt+F4 in mouse relative mode. Alt+F4 is disabled during captured cursor. if (viewport.MouseRelativeMode) { if (eKey == EKeys.F4 && viewport.IsKeyPressed(EKeys.Alt)) { EngineApp.NeedExit = true; return; } } if (viewport.IsKeyPressed(EKeys.Alt) && eKey == EKeys.Return) { EngineApp.SetFullscreenMode(!EngineApp.FullscreenEnabled, EngineApp.FullscreenSize); //App.FullScreen = !App.FullScreen; handled = true; } } //args.Handled = handled; } else if (args.EventType == CoreAcceleratorKeyEventType.KeyUp || args.EventType == CoreAcceleratorKeyEventType.SystemKeyUp) { bool handled = false; viewport.PerformKeyUp(new KeyEvent(eKey), ref handled); //args.Handled = handled; } else if (args.EventType == CoreAcceleratorKeyEventType.Character || args.EventType == CoreAcceleratorKeyEventType.UnicodeCharacter) { char keyChar = (char)args.VirtualKey; KeyPressEvent keyPressEvent = new KeyPressEvent(keyChar); bool handled = false; GetViewport()?.PerformKeyPress(keyPressEvent, ref handled); //args.Handled = handled; } }
/// <summary> /// Called when an accelerator key is pressed (i.e. a key with a Menu) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void DispatcherOnAcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs e) { if (e.EventType == CoreAcceleratorKeyEventType.KeyDown || e.EventType == CoreAcceleratorKeyEventType.SystemKeyDown) { if (!ActiveKeys.Contains(e.VirtualKey)) { ActiveKeys.Add(e.VirtualKey); } } else if (e.EventType == CoreAcceleratorKeyEventType.KeyUp || e.EventType == CoreAcceleratorKeyEventType.SystemKeyUp) { if (ActiveKeys.Contains(e.VirtualKey)) { CheckForActiveKey(); ActiveKeys.Remove(e.VirtualKey); } } }
private void Dispatcher_AcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs args) { if (args.EventType.ToString().Contains("Down")) { // 按下Esc键则退出图片详情 if (args.VirtualKey == Windows.System.VirtualKey.Escape) { foreach (var item in PopupUserControlList) { if (item.GetType() == typeof(ImageMaskControl)) { var t = (ImageMaskControl)item; t.Close(); break; } } } // 向左或向上切换上一张图片,没有则弹出提醒 else if (args.VirtualKey == VirtualKey.Left || args.VirtualKey == VirtualKey.Up) { foreach (var item in PopupUserControlList) { if (item.GetType() == typeof(ImageMaskControl)) { var t = (ImageMaskControl)item; var oldImg = t.imageFile; var groupimages = App.Db.Images.Where(p => p.GroupId == oldImg.GroupId).ToList(); int index = groupimages.IndexOf(oldImg); if (index != -1 && index > 0) { t.Init(groupimages[index - 1]); break; } else { new PopupMaskTip(AppTools.GetReswLanguage("IsFirstImage")).Show(); break; } } } } // 向右或向下切换下一张图片,没有则弹出提醒 else if (args.VirtualKey == VirtualKey.Right || args.VirtualKey == VirtualKey.Down) { foreach (var item in PopupUserControlList) { var t = (ImageMaskControl)item; var oldImg = t.imageFile; var groupimages = App.Db.Images.Where(p => p.GroupId == oldImg.GroupId).ToList(); int index = groupimages.IndexOf(oldImg); if (index != -1 && index < groupimages.Count - 1) { t.Init(groupimages[index + 1]); break; } else { new PopupMaskTip(AppTools.GetReswLanguage("IsLastImage")).Show(); break; } } } } }
private void CoreDispatcher_AcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs e) { if (e.EventType.ToString().Contains("Down") && !e.Handled) { var args = KeyboardEventArgs(e.VirtualKey); args.EventArgs = e; try { KeyDown?.Invoke(args); } finally { e.Handled = e.Handled; } } }
/// <summary> /// Invoked on every keystroke, including system keys such as Alt key combinations, when /// this page is active and occupies the entire window. Used to detect keyboard navigation /// between pages even when the page itself doesn't have focus. /// </summary> /// <param name="sender">Instance that triggered the event.</param> /// <param name="e">Event data describing the conditions that led to the event.</param> private void CoreDispatcher_AcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs e) { var virtualKey = e.VirtualKey; // Only investigate further when Left, Right, or the dedicated Previous or Next keys // are pressed 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)) { // When the previous key or Alt+Left are pressed navigate back e.Handled = true; this.GoBackCommand.Execute(null); } else if (((int)virtualKey == 167 && noModifiers) || (virtualKey == VirtualKey.Right && onlyAlt)) { // When the next key or Alt+Right are pressed navigate forward e.Handled = true; this.GoForwardCommand.Execute(null); } } }
/// <summary> /// Invoked on every keystroke, including system keys such as Alt key combinations. /// Used to detect keyboard navigation between pages. /// </summary> /// <param name="sender">Instance that triggered the event.</param> /// <param name="args">Event data describing the conditions that led to the event.</param> protected virtual void OnAcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs args) { }