简体   繁体   中英

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

I am working with C# and Windows Mobile .

I want to make a LeftSoftKey press trigger the "submit" action on a web page currently viewed in a WebBrowser window. In the HTML form being viewed there is a single form with an entry.

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. 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. The easiest way to do that would be to use an existing javascript framework like jquery.

The raw javascript code (without jquery) would be something like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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