forked from MattStultz/extrusiongen
-
Notifications
You must be signed in to change notification settings - Fork 1
/
IKRS.KeyEvent.js
52 lines (40 loc) · 1.17 KB
/
IKRS.KeyEvent.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* This is a wrapper class for javascript key events.
*
* Native javascript events are very simple and not comfortable
* to use.
*
* This adds some extra features to the event.
*
* @authos Ikaros Kappler
* @version 1.0.0
* @date 2014-08-11
**/
IKRS.KeyEvent = function( keyEvent ) {
IKRS.Object.call( this );
this.keyEvent = keyEvent;
};
IKRS.KeyEvent.prototype = new IKRS.Object();
IKRS.KeyEvent.prototype.constructor = IKRS.KeyEvent;
IKRS.KeyEvent.prototype.getKeyCode = function() {
return this.keyEvent.keyCode;
};
IKRS.KeyEvent.prototype.isShiftKey = function() {
return this.keyEvent.keyCode == 16;
};
IKRS.KeyEvent.prototype.isControlKey = function() {
return this.keyEvent.keyCode == 17;
};
IKRS.KeyEvent.prototype.isAltKey = function() {
return this.keyEvent.keyCode == 18;
};
/**
* Pass a character (one-character string) and the function checks
* if the passed character matches this event's key code.
**/
IKRS.KeyEvent.prototype.isCharacterKey = function( character ) {
if( character.length == 0 )
return false;
else
return this.keyEvent.keyCode == character.substring(0,1).toUpperCase().charCodeAt(0);
};