Partager via


onkeypress Event

  Microsoft Speech Technologies Homepage

Occurs each time a grammar-defined dual tone multi-frequency (DTMF) key is pressed.

HTML <dtmf onkeypress="keypressHandler()">
Scripting dtmf.onkeypress = keyPressHandler;
Named Script <SCRIPT FOR = dtmf EVENT = onkeypress>

Remarks

For HTML and XHTML, the onkeypress event overrides the default onkeypress event inherited from the HTML control. Only DTMF keypresses raise this event for the dtmf element.

Immediately before raising the onkeypress event, the value of the pressed key is appended to the text property string of the dtmf element. If a prompt playback is in progress, the onkeypress event raises the onbargein event on the prompt. The prompt stops playback if its bargein attribute is set to true. If a listen element is active, the first onkeypress event disables the initialtimeout period of any active listen element.

Keys other than those defined in the grammar raise an onnoreco event.

Example

The following code demonstrates the use of the onkeypress event.

<html xmlns:salt="http://www.saltforum.org/2002/SALT">
  ...
  <body>
    <input type="text" name="iptAreaCode" onFocus="dtmfAreaCode.Start()" />
    <input type="text" name="iptPhoneNumber" />
    ...
    <salt:dtmf id="dtmfAreaCode" onkeypress="dtmfKeyPressHandler()" onreco="dtmfPhoneNumber.Start()"    onsilence="dtmfSilenceHandler()" onerror="dtmfErrorHandler()" onnoreco="dtmfErrorHandler()"    initialtimeout="5000" interdigittimeout="2000" preflush="true">
      <!-- grammar result will contain "smlAreaCode" node -->
      <salt:grammar src="3digits.grxml" />
      <salt:bind value="//smlAreaCode" targetelement="iptAreaCode" />
    </salt:dtmf>
    <salt:dtmf id="dtmfPhoneNumber" onkeypress="dtmfKeyPressHandler()" onerror="dtmfErrorHandler()"    initialtimeout="5000" interdigittimeout="2000" preflush="true">
       <!-- grammar result will contain "smlPhoneNumber" node -->
      <salt:grammar src="7digits.grxml" />
      <salt:bind value="//smlPhoneNumber" targetelement="iptPhoneNumber" />
    </salt:dtmf>
    <script language="jscript">
    <!--
      function dtmfSilenceHandler() {
        ...
      }
  
      function dtmfErrorHandler() {
        ...
      }
      
      function dtmfKeyPressHandler() {
        ...
      }
      -->
      </script>
  <body>
</html>

See Also

dtmf Element |  prompt Element | listen Element | onbargein Event | text Property | bargein Attribute