Click to return to the Component Development home page    
Welcome to Scriptlet Tech...    
Web Workshop  |  Component Development

Handling Standard Events


The scriptlet can expose these standard DHTML events:

onclickonkeypressonmousemove
ondblclickonkeyuponmouseup
onkeydownonmousedown

Tip You can define a context menu that is displayed when the user right-clicks the scriptlet at run time. For more information, see the setContextMenu method.

To work with standard events in the host application, you must write handlers in two places: one in the scriptlet to send the event, and another in the host application to capture the event.

To pass an event from the scriptlet to the host application:

  1. Attach an event handler script to the event that you want to pass.
  2. Within the event handler script, call the bubbleEvent method to send the event to the host application.

    Note Before passing events to the container object, you can check the scriptlet's frozen property to be sure that the container object is ready to handle events.

If the scriptlet does not include an event handler for a specific event, that event will not be passed to the host application. Similarly, if the scriptlet includes a handler for the event but does not call the bubbleEvent method, the event will not be visible to the host application.

Note The scriptlet container object exposes all standard events at design time, even if the scriptlet does not contain a script that passes the standard event to the application. For example, in Microsoft Visual Basic®, the code window for the scriptlet container lists all standard events, even if not all are available in a specific scriptlet.

The following scriptlet script shows how you can pass a text box's onkeyup event to the host application.

<INPUT TYPE=text ONKEYUP="passKeyUp()" NAME="t1" VALUE="">

<SCRIPT LANGUAGE="JavaScript">
function passKeyUp() {
   // script statements here if required
    window.external.bubbleEvent();
   // further script statements here if required
}
</SCRIPT>

In the host application, the corresponding event is triggered for the scriptlet container object. Additional information about the event, such as the location of the mouse pointer or the state of keys at the time the event was triggered, is available in the script container object's event property. For example, the following Visual Basic subroutine shows how you would capture the scriptlet's onkeypress event and display the key code of a character typed in a scriptlet text box.

Sub ScriptContainer1_onkeyup()
   MsgBox "The character typed was " & ScriptContainer1.event.keyCode
   MsgBox "The shift state was " & ScriptContainer1.event.shiftKey
End Sub

In Microsoft Internet Explorer, the following script does the same thing:

<SCRIPT LANGUAGE=JavaScript FOR=document EVENT=onkeyup>
   alert("Key code = " + window.event.keyCode)
   alert("Shift status  = " + window.event.shiftKey)
</SCRIPT>

See Also

Defining Custom Events



Back to topBack to top

Did you find this topic useful? Suggestions for other topics? Write us!

© 1999 Microsoft Corporation. All rights reserved. Terms of use.