Class Index | File Index

Classes


Namespace $.dom.KeyboardEvent

Holds a DOM Keyboard Event method which provides a simple way to determine the key the user pressed.
Defined in: core-dom.js.

Namespace Summary
Constructor Attributes Constructor Name and Description
 
Holds a DOM Keyboard Event method which provides a simple way to determine the key the user pressed.
Method Summary
Method Attributes Method Name and Description
<static>  
$.dom.KeyboardEvent.getKey()
This method returns the character / key identifier for the current keyboard event.
Namespace Detail
$.dom.KeyboardEvent
Holds a DOM Keyboard Event method which provides a simple way to determine the key the user pressed.

By default, the global KeyboardEvent.prototype object is extended to contain the method defined in this namespace. If the KeyboardEvent object is not available in the browser, then the Event.prototype object is extended.

The getKey() method uses the this object to refer to the current event. As such, you need to pass the correct this object.

In the examples provided we will assume that the objects defined are already extended. Thus, code like ev.getKey() can be written directly.

For more advanced keyboard event handling needs, please check out the $.dom.KeyboardEventListener class.

var klogger = function (ev) {
  console.log(ev.type + ' key ' + ev.getKey());
};

window.addEventListener('keydown',  klogger, false);
window.addEventListener('keypress', klogger, false);
window.addEventListener('keyup',    klogger, false);
Method Detail
<static> {String} $.dom.KeyboardEvent.getKey()
This method returns the character / key identifier for the current keyboard event.

Some of the key identifiers this method returns are listed in the DOM 3 Events specification. The notable differences are that this method uses names for several of the Unicode characters in that list:

Additionally, all Unicode characters of the form 'U+XXXX' are converted to the actual character. For example 'U+0053' becomes 'S'.

This method is known to work in Opera, Firefox, Chrome, Safari, MSIE 8 and Konqueror.

For more advanced keyboard event handling, please check $.dom.KeyboardEventListener.

var dialog_keydown = function (ev) {
  var key = ev.getKey();
  if (key == 'F1') {
    // show help
  } else if (key == 'Escape') {
    // close dialog
  } else if (key == 'Enter') {
    // accept changes and close dialog
  }
};

window.addEventListener('keydown', dialog_keydown, false);
Returns:
{String} The character / key identifier for the current keyboard event. If the key is unrecognized null is returned.
See:
$.dom.KeyboardEventListener The more advanced keyboard event compatibility layer.

Documentation generated by JsDoc Toolkit 2.1.0 on Thu Apr 23 2009 13:05:50 GMT+0300 (EEST)