c# - 从 Silverlight 覆盖 (IE7) 浏览器键盘处理

标签 c# javascript silverlight internet-explorer internet-explorer-7

当我在 Firefox 中测试 Silverlight 2 应用程序时,当 Silverlight 具有焦点时,我可以毫无问题地通过 Page.KeyDown 事件接收每个按键。

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

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

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

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

...

initKeyHandling();

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

最佳答案

从文档看来这是不可能的(至少没有像你提到的那样的 javascript 解决方案):

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.

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 文本框的解决方法。但我不确定它是否仍然支持,或者细节是什么。如果我再次找到它,我会回来的。

/阿斯格

关于c# - 从 Silverlight 覆盖 (IE7) 浏览器键盘处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/769668/

相关文章:

c# - 更新查询需要删除并重新插入所有相关项目,这会降低我的应用程序的速度

c# - 更改代码优先 Entity Framework 中的列名称?

javascript - jstree 中不同的 TreeView 图标和启用/禁用复选框

silverlight - 两种方式将复选框绑定(bind)到 Silverlight 中的 bool 属性

silverlight - 如何在 Silverlight 中将工具提示置于我的控件之上?

Silverlight:如何设置验证工具提示的样式?

c# - 协作环境中 Entity Framework 中的迁移

c# - 如何更新 ASPNetCoreRateLimit lib 的重试后值?

javascript - 也调用函数onload和onscroll吗?

javascript - 语义 UI 动态下拉菜单