• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)

Use dojo/keys For Key Press Events in DOJO

October 9, 2013 //  by Krishna Srinivasan//  Leave a Comment

If you are working in JavaScript, getting the key press events is necessary to perform any user initiated operations. DOJO provides dojo/keys module to perform all the key events. dojo/keys module defines the constants for each type of key with the corresponding key code. This helps us to import this module and directly use it in our code. Almost all the important keys are defined in this module. Look at the below example to understand how to use this module to capture the key events.

[code lang=”html”] <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script>
var dojoConfig = {
baseUrl : "src",
packages : [ {
name : "dojo",
location : "dojo"
}, {
name : "dijit",
location : "dijit"
}, {
name : "dojox",
location : "dojox"
}, {
name : "app",
location : "app"
}, ],
parseOnLoad : true,
async : true
};
</script>
<script src="src/dojo/dojo.js"></script>
<script>
require(["dojo/on",
"dojo/keys",
"dojo/domReady!"],
function(on, keys, dom){
on(document, "keyup", function(event){
alert (event.keyCode);
switch (event.keyCode)
{
case keys.UP_ARROW:
alert ("Up Arrow Pressed!!");
break;
case keys.DOWN_ARROW:
alert ("Down Arrow Pressed!!");
break;
case keys.ENTER:
alert ("Enter Pressed!!");
break;
}
});
});
</script>
</head>
<body>
<h1>Enter Value</h1>
<input type="text" id="keyCode" size="2">
</body>
</html>
[/code]

The above example is easy to understand how to capture the key press events on DOJO application.

Category: DOJOTag: dojotoolkit

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Previous Post: « Basics of Java Interface Usage
Next Post: JSON Processing in JavaEE 7- Using Streaming API »

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

np.zeros

A Complete Guide To NumPy Functions in Python For Beginners

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact