Class glow.events.KeyboardEvent
Extends
glow.events.DomEvent.
Defined in: core.js.
| Constructor Attributes | Constructor Name and Description |
|---|---|
|
glow.events.KeyboardEvent(nativeEvent, properties)
Describes a keyboard event.
|
| Field Attributes | Field Name and Description |
|---|---|
|
The key pressed
This is a string representing the key pressed.
|
|
|
The character entered.
|
- Fields borrowed from class glow.events.DomEvent:
- altKey, button, ctrlKey, mouseLeft, mouseTop, nativeEvent, related, shiftKey, source, type, wheelData
- Fields borrowed from class glow.events.Event:
- attachedTo
- Methods borrowed from class glow.events.DomEvent:
- stopPropagation
- Methods borrowed from class glow.events.Event:
- defaultPrevented, preventDefault
Class Detail
glow.events.KeyboardEvent(nativeEvent, properties)
Describes a keyboard event.
You don't need to create instances of this class if you're simply
listening to events. One will be provided as the first argument
in your callback.
- Parameters:
- {Event} nativeEvent
- A native browser event read properties from.
- {Object} properties Optional
- Properties to add to the Event instance. Each key-value pair in the object will be added to the Event as properties.
Field Detail
key
The key pressed
This is a string representing the key pressed.
Alphanumeric keys are represented by 0-9 and a-z (always lowercase). Other safe cross-browser values are:
- backspace
- tab
- return
- shift
- alt
- escape
- space
- pageup
- pagedown
- end
- home
- left
- up
- right
- down
- insert
- delete
- ;
- =
- -
- f1
- f2
- f3
- f4
- f5
- f6
- f7
- f8
- f9
- f10
- f11
- f12
- numlock
- scrolllock
- pause
- ,
- .
- /
- [
- \
- ]
glow(document).on('keypress', function(event) {
switch (event.key) {
case 'up':
// do stuff
break;
case 'down':
// do stuff
break;
}
});
keyChar
The character entered.
This is only available during 'keypress' events.
If the user presses shift and 1, event.key will be "1", but event.keyChar
will be "!".
// only allow numbers to be entered into the ageInput field
glow('#ageInput').on('keypress', function(event) {
// Convert keyChar to a number and see if we get
// a valid number back
return !isNaN( Number(event.keyChar) );
});