从Silverlight覆盖(IE7)浏览器键盘处理 [英] Override (IE7) browser keyboard handling from Silverlight

查看:127
本文介绍了从Silverlight覆盖(IE7)浏览器键盘处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Firefox中测试我的Silverlight 2应用程序时,当Silverlight有焦点时,我通过Page.KeyDown事件接收每个按键都没有问题。

When I test my Silverlight 2 app in Firefox, when Silverlight has focus, I have no problem receiving every key press via the Page.KeyDown event.

当我在Internet Explorer 7中测试它,我只能获得浏览器尚未处理的键盘事件。但是,我可以在javascript中覆盖那些相同的键盘事件。

When I test it in Internet Explorer 7, I can only get keyboard events that the browser doesn't already handle. HOWEVER, I can override those same keyboard events in javascript.

例如, Ctrl + D 。我可以通过执行以下操作在 javascript 中覆盖它,但我无法在Silverlight中执行相同的操作!!

For instance, Ctrl + D. I can override this in javascript by doing the following, but I can't do the same thing in Silverlight!!

function initKeyHandling(){ document.attachEvent("onkeydown", keydown); }

function keydown(e) { printToTextbox('Keydown ', e); return false; }

...

initKeyHandling();

此外,我尝试将事件从Javascript转发到Silverlight失败了。当Silverlight具有焦点时,我的javascript键盘事件处理程序甚至不会被触发。

Furthermore, my attempts to forward the events from Javascript to Silverlight have failed. My javascript keyboard event handlers never even get fired when Silverlight has focus.

推荐答案

从文档中看来它是不可能的(至少没有像你提到的javascript工作):

From the docs it seems that it is not possible (at least without a javascript work around like you are mentioning):


键盘事件和浏览器
不同的浏览器可能会处理
键盘事件不同。当你
创建一个使用
键盘输入的应用程序时,请确保在目标浏览器中测试
应用程序。

Keyboard Events and the Browser Different browsers might handle keyboard events differently. When you create an application that uses keyboard input, make sure to test the application in your target browsers.

浏览器确定它解释为命令
的哪个
键击以及它传递给
托管内容的哪些键击。这意味着无法从KeyDown和KeyUp事件处理程序
函数中检索
某些击键

浏览器解释为命令的大多数击键是
快捷键或加速键击,
并且不作为关键事件传递给
Silverlight。例如,CTRL + D是一个
快捷键组合,用于
将最喜欢的URL添加到Firefox
和Internet Explorer浏览器中,而
则不会将CTRL和D报告为$
关键事件。

The browser determines which keystrokes it interprets as commands and which keystrokes it passes on to hosted content. This means that certain keystrokes cannot be retrieved from KeyDown and KeyUp event-handler functions. Most keystrokes that a browser interprets as commands are shortcut or accelerator keystrokes, and are not passed as key events to Silverlight. For example, CTRL+D is a shortcut keystroke combination for adding a favorite URL to the Firefox and Internet Explorer browsers, and neither CTRL nor D is reported as a key event.

看看: http://msdn.microsoft.com/en-us/library/cc189015.aspx

我想我前几天阅读了有关基础HTML文本框的工作。但我不确定它是否仍然受到支持,或者细节是什么。如果我再找到它,我会回来的。

I think I read about a work around with an underlying HTML textbox the other day. But I'm not sure if it still supported, or what the details were. I will return if I find it again.

/ Asger

这篇关于从Silverlight覆盖(IE7)浏览器键盘处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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