如果webview具有焦点,我怎样才能获得键盘事件? [英] How can I get keyboard events if a webview has focus?

查看:77
本文介绍了如果webview具有焦点,我怎样才能获得键盘事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个Windows 8应用程序,该应用程序旨在利用映射到键盘按键的外部硬按钮来实现某些交互功能(这是在需要禁用触摸的情况下的概念证明)。  其中一个页面是全屏
webview。  页面加载后,webview成为焦点,无法监视任何键盘输入,因为webview似乎没有将任何事件传递到页面级别。  这使得无法导航到应用程序中的任何其他页面


是否有办法获取键盘事件或至少某些键盘按键组合时webview有焦点吗?   webview正在显示外部页面,因此我无法使用javascript事件。  这是我当前的代码,寻找一个永远不会被触发的转义键

 public sealed partial class Map:Page 
{
protected override void OnNavigatedTo(NavigationEventArgs e)
{
Window.Current.CoreWindow.KeyUp + = Window_KeyUp;
}

公共地图()
{
this.InitializeComponent();
Uri mapUri = new Uri(@" http://www.bing.com/maps/");
mapWebView1.Navigate(mapUri);
}

void Window_KeyUp(Windows.UI.Core.CoreWindow sender,Windows.UI.Core.KeyEventArgs e)
{
if(e.VirtualKey == Windows.System.VirtualKey.Escape)
{
this.Frame.Navigate(typeof(MainPage));
}
}

protected override void OnNavigatedFrom(NavigationEventArgs e)
{
Window.Current.CoreWindow.KeyUp - = Window_KeyUp;
}
}

解决方案

如果你无法获得CoreWindow事件,那么你将无法获得它们。你可能会在Windows 8.1的WebView上获得更好的行为,但我还没有尝试过。


我认为这里的地图只是一个占位符。如果真正的用途是专门用于地图,那么你可以直接使用地图控件而不是WebView。


- Rob




I'm building a Windows 8 application that is designed to make use of external hard buttons mapped to keyboard keys for some interaction features (it's a proof of concept for situations where it's necessary to disable touch).  One of the pages is a full-screen webview.  After the page loads, the webview takes focus and it becomes impossible to monitor any keyboard input because the webview doesn't seem to pass any of the events up to the page level.  This makes it impossible to navigate to any other pages in the application.

Is there a way to get keyboard events or at least some combination of keyboard key presses when a webview has focus?  The webview is displaying external pages, so I can't use javascript events.  Here is my current code, looking for an escape keyUp that is never fired:

public sealed partial class Map : Page
    {
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            Window.Current.CoreWindow.KeyUp += Window_KeyUp;
        }

        public Map()
        {
            this.InitializeComponent();
            Uri mapUri = new Uri(@"http://www.bing.com/maps/");
            mapWebView1.Navigate(mapUri);
        }

        void Window_KeyUp(Windows.UI.Core.CoreWindow sender, Windows.UI.Core.KeyEventArgs e)
        {
            if (e.VirtualKey == Windows.System.VirtualKey.Escape)
            {
                this.Frame.Navigate(typeof(MainPage));
            }
        }

        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            Window.Current.CoreWindow.KeyUp -= Window_KeyUp;
        }
    }

解决方案

If you can't get the CoreWindow events then you won't be able to get them. You might get better behavior on Windows 8.1's WebView, but I haven't tried it.

I assume the map here is just a placeholder. If the real use is specifically for maps then you can use the map controls directly rather than in a WebView.

--Rob



这篇关于如果webview具有焦点,我怎样才能获得键盘事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆