app如何从底层监听Win8系统的鼠标消息和键盘消息
2012-07-06 15:11
435 查看
// Keyboard and mouse navigation only apply when occupying the entire window if (this.ActualHeight == Window.Current.Bounds.Height && this.ActualWidth == Window.Current.Bounds.Width) { // Listen to the window directly so focus isn't required Window.Current.CoreWindow.Dispatcher.AcceleratorKeyActivated += CoreDispatcher_AcceleratorKeyActivated; Window.Current.CoreWindow.PointerPressed += this.CoreWindow_PointerPressed; }
/// <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="args">Event data describing the conditions that led to the event.</param> private void CoreDispatcher_AcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs args) { var virtualKey = args.VirtualKey; // Only investigate further when Left, Right, or the dedicated Previous or Next keys // are pressed 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)) { // When the previous key or Alt+Left are pressed navigate back args.Handled = true; this.GoBack(this, new RoutedEventArgs()); } else if (((int)virtualKey == 167 && noModifiers) || (virtualKey == VirtualKey.Right && onlyAlt)) { // When the next key or Alt+Right are pressed navigate forward args.Handled = true; this.GoForward(this, new RoutedEventArgs()); } } } /// <summary> /// Invoked on every mouse click, touch screen tap, or equivalent interaction when this /// page is active and occupies the entire window. Used to detect browser-style next and /// previous mouse button clicks to navigate 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> private void CoreWindow_PointerPressed(CoreWindow sender, PointerEventArgs args) { var properties = args.CurrentPoint.Properties; // Ignore button chords with the left, right, and middle buttons if (properties.IsLeftButtonPressed || properties.IsRightButtonPressed || properties.IsMiddleButtonPressed) return; // If back or foward are pressed (but not both) navigate appropriately bool backPressed = properties.IsXButton1Pressed; bool forwardPressed = properties.IsXButton2Pressed; if (backPressed ^ forwardPressed) { args.Handled = true; if (backPressed) this.GoBack(this, new RoutedEventArgs()); if (forwardPressed) this.GoForward(this, new RoutedEventArgs()); } }
相关文章推荐
- Node监听鼠标键盘事件,定时发消息小程序,解决robotjs不支持输入汉字问题!
- [Angular] 键盘监听事件需要鼠标点击一下窗口才能监听到如何解决?
- 通过监听Windows消息实现控件的键盘和鼠标事件路由
- 如何在ArcMap中监听键盘鼠标事件(转)
- 如何在ArcMap中监听键盘鼠标事件
- 如何在C#.Net中获取、屏蔽鼠标键盘消息?
- 如何在ArcMap中监听键盘鼠标事件
- 如何通过鼠标或者键盘监听器,实现组建特有的监听方法
- Python中使用PyHook监听鼠标和键盘事件实例
- [译]如何在Linux下禁用键盘、触摸板、鼠标等输入设备
- c# 如何获取键盘和鼠标处于空闲状态的时间
- Android App监听软键盘按键的三种方式
- MFC中键盘,鼠标等有用的消息函数。
- Java基础--Java---IO流------GUI(布局)、Frame、事件监听机制、窗体事件、Action事件、鼠标事件、对话框Dialog、键盘事件、菜单
- win32(4)--鼠标及键盘消息
- 如何在Java程序内实现键盘监听?
- (转)Android App监听软键盘按键的三种方式
- 如何在C#中使用全局鼠标、键盘Hook
- QT:如何获取鼠标坐标点和键盘响应事件
- win7升级win8系统后鼠标间歇性失灵如何解决