为什么C#webbrowser控件获取jquery keydown事件而不是keypress直到手动点击控件? [英] Why C# webbrowser control gets jquery keydown event and not keypress until manual clicking control?

查看:100
本文介绍了为什么C#webbrowser控件获取jquery keydown事件而不是keypress直到手动点击控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果需要,我可以提供示例代码,但还没有完成。



总结虽然我很困惑如何设置一个C#/ .NET代码中的全局热键(使用pinvoke win32调用),当触发时打开一个只有webbrowser控件+调用的表单(在表单_Load()方法中):



this.BringToFront();

this.Activate();

this.Focus();

webBrowser1.Focus() ;

this.ActiveControl = webBrowser1;

webBrowser1.Document.InvokeScript(document.getElementsByTagName('div')[0] .focus();); < br $>


导致表单显示+响应来自jQuery keydown处理程序的关键事件,但jQuery keypress处理程序不起作用,直到我通常用鼠标单击浏览器控件。



现在我通过使用ProcessCmdKey()重载方法处理这个表单来调用web浏览器js方法并注入类型文本,但这很难看喜欢 如何很难检测到 - ,!,@等键的字符(目前它们只是不起作用)



我甚至在javascript中尝试过做window.addEventListener(按键,...



,除非我手动点击它,否则直到我点击网页浏览器控件才会发生该事件。



但并非每次都有。我注意到,如果我点击桌面图标然后执行热键序列之后我的桌面处于活动状态,那么按键事件就可以了。但似乎当热键序列发生时,我有任何其他程序处于活动状态,然后弹出窗体出现,只有keydown事件有效。



非常混乱。 />


任何想法如何修复所以javascript keypress事件可以使用?



谢谢!



我的尝试:



开头:



this.Focus();

webBrowser1.Focus();



正在努力:



this.BringToFront();

this.Activate();

this.Focus();

webBrowser1.Focus();

this.ActiveControl = webBrowser1;

webBrowser1.Document.InvokeScript(document.getElementsByTagName('div')[ 0] .focus(););





也是以jQuery 3.1.1 $(文档).keypress()处理程序开始的并按我的方式降低到window.addEventListener(keypress,函数(e){...



我实现了一些pinvoke代码模拟鼠标点击,但它似乎没有正常工作,除非我真的移动光标的位置,这对于已发布的产品来说非常尴尬。



现在使用表单ProcessCmdKey()重载函数处理文本键输入,空格键和退格键,但是尝试处理更多键(例如数字的移位版本(!,@,#,$,%,^ ...)很尴尬。)

I can come up with sample code if needed, but haven't done that yet.

In summary though I'm very confused how my setting up a global hotkey in C# / .NET code (using pinvoke win32 calls) that when triggered opens a form that has just a webbrowser control + calls (in forms _Load() method):

this.BringToFront();
this.Activate();
this.Focus();
webBrowser1.Focus();
this.ActiveControl = webBrowser1;
webBrowser1.Document.InvokeScript("document.getElementsByTagName('div')[0].focus();");

leads to the form being shown + responding to key events from jQuery keydown handler, yet the jQuery keypress handler doesn't work until I click the browser control with the mouse usually.

For now I handled this via using the ProcessCmdKey() overloaded method for the form to call a web browser js method and inject typed text that way, but it's ugly like with how it's hard to detect the character for keys like -, !, @, ... (currently they just don't work)

I even tried in javascript doing window.addEventListener("keypress",...

and still that event doesn't come until I click the web browser control typically unless I manually click it.

It's not every time though. I've noticed that it seems like if I had my desktop active like right after clicking a desktop icon then doing hotkey sequence, then the keypress event works right. But it seems if I had any other program active when the hotkey sequence happened, then the popup form comes up and only the keydown event works.

Very confusing.

Any ideas how to fix so javascript keypress event can be used?

Thanks!

What I have tried:

Started with:

this.Focus();
webBrowser1.Focus();

working up to:

this.BringToFront();
this.Activate();
this.Focus();
webBrowser1.Focus();
this.ActiveControl = webBrowser1;
webBrowser1.Document.InvokeScript("document.getElementsByTagName('div')[0].focus();");


Also started with jQuery 3.1.1 $(document).keypress() handler and worked my way lower to window.addEventListener("keypress", function(e){...

I implemented some pinvoke code to simulate a mouse click, but it doesn't seem to work right unless I literally move the position of the cursor and that's very awkward appearing for a published product.

For now using the forms ProcessCmdKey() overloaded function is handling text key input, spacebar, and backspace, but it's awkward trying to handle more keys like the shift version of numbers (!,@,#,$,%,^....)

推荐答案

(文档).keypress()处理程序并以我的方式降低到window.addEventListener(keypress,function(e){... < br $>


我实现了一些pinvoke代码来模拟鼠标点击,但它似乎没有正常工作,除非我字面上移动光标的位置,这是非常尴尬的出现已发布的产品。



现在使用表单ProcessCmdKey()重载函数正在处理文本键输入,空格键和退格键,但是尝试处理更多的键是很尴尬的转变版数字sion(!,@,#,
(document).keypress() handler and worked my way lower to window.addEventListener("keypress", function(e){...

I implemented some pinvoke code to simulate a mouse click, but it doesn't seem to work right unless I literally move the position of the cursor and that's very awkward appearing for a published product.

For now using the forms ProcessCmdKey() overloaded function is handling text key input, spacebar, and backspace, but it's awkward trying to handle more keys like the shift version of numbers (!,@,#,


,%,^ ....)


这篇关于为什么C#webbrowser控件获取jquery keydown事件而不是keypress直到手动点击控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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