简体   繁体   English

如何在C#中的Windows Mobile中触发来自keydown事件的提交

[英]How to Trigger a submit from keydown event in Windows Mobile in C#

I am working with C# and Windows Mobile . 我正在使用C#和Windows Mobile

I want to make a LeftSoftKey press trigger the "submit" action on a web page currently viewed in a WebBrowser window. 我想让LeftSoftKey按下以在当前在WebBrowser窗口中查看的网页上触发“提交”操作。 In the HTML form being viewed there is a single form with an entry. 在正在查看的HTML表单中,有一个带有条目的表单。

Currently I can capture the left soft key keydown event. 目前,我可以捕获到左软键按下事件。 What I can not find is how to either invoke, or trigger the WebBrowser to act as though either the submit button was pressed, or alternately the "enter" key was pressed causing the default submission. 我找不到的是如何调用或触发WebBrowser以使其好像按下了“提交”按钮一样,或者按下“输入”键导致默认的提交。 Either is an acceptable action. 两者都是可以接受的动作。

You'll need to write some javascript for the webpage on that listens to the key-press and then submits the FORM programatically. 您需要为网页编写一些javascript,以监听按键,然后以编程方式提交FORM。 The easiest way to do that would be to use an existing javascript framework like jquery. 最简单的方法是使用现有的javascript框架(例如jquery)。

The raw javascript code (without jquery) would be something like this: 原始的javascript代码(没有jquery)将如下所示:

<script type="text/javascript">
document.onkeyup = handleKeyPress;
function handleKeyPress() {
 switch (event.keyCode) {
    case 25: // some number corresponding to your desired key
     // do something;
  }
}
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM