KeyListener Example : Key Listener « Ajax Layer « JavaScript DHTML

JavaScript DHTML
1. Ajax Layer
2. Data Type
3. Date Time
4. Development
5. Document
6. Dojo toolkit
7. Event
8. Event onMethod
9. Ext JS
10. Form Control
11. GUI Components
12. HTML
13. Javascript Collections
14. Javascript Objects
15. Javascript Properties
16. jQuery
17. Language Basics
18. Mochkit
19. Mootools
20. Node Operation
21. Object Oriented
22. Page Components
23. Rico
24. Scriptaculous
25. Security
26. SmartClient
27. Style Layout
28. Table
29. Utilities
30. Window Browser
31. YUI Library
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
JavaScript DHTML » Ajax Layer » Key Listener 
KeyListener Example

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>YAHOO.util.KeyListener</title>

<script type="text/javascript" src="./build/yahoo/yahoo.js" ></script>
<script type="text/javascript" src="./build/event/event.js" ></script>
<script type="text/javascript" src="./build/dom/dom.js" ></script>

<link rel="stylesheet" type="text/css" href="./build/fonts/fonts.css" />
<link rel="stylesheet" type="text/css" href="./examples/container/css/example.css" />

<script type="text/javascript" src="./build/container/container_core.js"></script>

<style>
</style>

<script language="javascript">
  
  YAHOO.namespace("example.keylistener");

  function init() {
    var debug = document.getElementById("debug");

    document.documentElement.focus();
    document.body.focus();

    var handler = function(type, args, obj) {
      debug.appendChild(document.createTextNode("key press handled: " + args[0]));
      debug.appendChild(document.createElement("BR"));
    }

    YAHOO.example.keylistener.kpl1 = new YAHOO.util.KeyListener(document, keys:[49,50,51] }fn:handler } );
    YAHOO.example.keylistener.kpl1.enable();

    YAHOO.example.keylistener.kpl2 = new YAHOO.util.KeyListener(document, shift:true, alt:true, keys:[52,53,54,55] }, handler );
    YAHOO.example.keylistener.kpl2.enable();
  }

  YAHOO.util.Event.addListener(window, "load", init);

</script>

</head>
<body>
  <div class="box">
    <div class="hd">
      <h1>KeyListener Example</h1>
    </div>
    <div class="bd">
    <p>KeyListener takes three arguments: the element reference or id to attach the listener to, an object literal that contains the details about the key(sto listen for, and the handler (represented either as a function, or a literal containing arguments for the handler function, the scope, and a scope correction flag).</p>
    <p>KeyListeners are enabled and disabled by calling the enable() and disable() functions on a listener. The DOM events for keys are dynamically attached and detached upon enable and disable. 
    </p>
    <p>Press 12to trigger KeyListener1.<button onclick="YAHOO.example.keylistener.kpl1.disable()">disable kpl1</button><button onclick="YAHOO.example.keylistener.kpl1.enable()">enable kpl1</button></p>
    <p>Press Alt+Shift+(456, or 7to trigger KeyListener2.<button onclick="YAHOO.example.keylistener.kpl2.disable()">disable kpl2</button><button onclick="YAHOO.example.keylistener.kpl2.enable()">enable kpl2</button></p>
    </div>
    <div id="debug">
    </div>
  </div>
</body>
</html>


           
       
yui.zip( 3,714 k)
Related examples in the same category
1. Capturing Hotkeys
2. Layer key event Demo
3. Catches and manages the keyboard's events
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.