Lounge - webbrowser control

Asked By lokesh on 27-Jul-11 08:01 AM
How to write webbrowser control  keypress event?
Jitendra Faye replied to lokesh on 27-Jul-11 08:04 AM
Use this code-

SHDocVw.IWebBrowser2 webBrowser;

mshtml.HTMLDocument doc;

mshtml.HTMLDocumentEvents2_Event iEvent;

//Get the underlying base native browser control

webBrowser = this.browserControl.ActiveXInstance as SHDocVw.IWebBrowser2;

if (webBrowser == null)

return;

// Get the Htmldocument

doc = webBrowser.Document as mshtml.HTMLDocument;

if (doc == null)

return;

iEvent = doc as mshtml.HTMLDocumentEvents2_Event;

if(iEvent!=null)

iEvent.onkeydown += new mshtml.HTMLDocumentEvents2_onkeydownEventHandler(KeyDownEventHandler);

Reena Jain replied to lokesh on 27-Jul-11 08:06 AM
Hi,

use this on keypress event

object oEmpty = "";
axWebBrowser1.Navigate2(ref oURL, ref oEmpty, ref oEmpty, ref oEmpty, ref oEmpty);

hope this will help you
Riley K replied to lokesh on 27-Jul-11 08:07 AM
Using onkeyup we can easily handle the key pressing event in Internet Explorer. Here is the script we need to capture some of the keys on the keyboard:


Here is an Example

<script type="text/javascript">
 
document.onkeyup = KeyCheck;    
 
function KeyCheck()
 
{
 
   var KeyID = event.keyCode;
 
 
   switch(KeyID)
 
   {
 
    case 16:
 
    document.Form1.KeyName.value = "Shift";
 
    break;
 
    case 17:
 
    document.Form1.KeyName.value = "Ctrl";
 
    break;
 
    case 18:
 
    document.Form1.KeyName.value = "Alt";
 
    break;
 
    case 19:
 
    document.Form1.KeyName.value = "Pause";
 
    break;
 
    case 37:
 
    document.Form1.KeyName.value = "Arrow Left";
 
    break;
 
    case 38:
 
    document.Form1.KeyName.value = "Arrow Up";
 
    break;
     
   }
}
</script>
 use the below HTML
<form name="Form1">
 
<input type="text" name="KeyName" value="" />
 
</form>

Try this and let me know
Riley K replied to lokesh on 27-Jul-11 08:07 AM
Using onkeyup we can easily handle the key pressing event in Internet Explorer. Here is the script we need to capture some of the keys on the keyboard:


Here is an Example

<script type="text/javascript">
 
document.onkeyup = KeyCheck;    
 
function KeyCheck()
 
{
 
   var KeyID = event.keyCode;
 
 
   switch(KeyID)
 
   {
 
    case 16:
 
    document.Form1.KeyName.value = "Shift";
 
    break;
 
    case 17:
 
    document.Form1.KeyName.value = "Ctrl";
 
    break;
 
    case 18:
 
    document.Form1.KeyName.value = "Alt";
 
    break;
 
    case 19:
 
    document.Form1.KeyName.value = "Pause";
 
    break;
 
    case 37:
 
    document.Form1.KeyName.value = "Arrow Left";
 
    break;
 
    case 38:
 
    document.Form1.KeyName.value = "Arrow Up";
 
    break;
     
   }
}
</script>
 use the below HTML
<form name="Form1">
 
<input type="text" name="KeyName" value="" />
 
</form>

Try this and let me know