Module gamejs/event
Mouse and keyboard events.
All events have a type identifier. This event type is in between the values
of NOEVENT and NUMEVENTS. Each event has a constant in gamejs.event.*
All user defined events can have the value of USEREVENT or higher.
Make sure your custom event ids* follow this system.
Example
gamejs.onEvent(function(event) {
if (event.type === gamejs.event.MOUSE_UP) {
gamejs.log(event.pos, event.button);
} else if (event.type === gamejs.event.KEY_UP) {
gamejs.log(event.key);
}
});
Properties
- DISPLAY_FULLSCREEN_DISABLED
- DISPLAY_FULLSCREEN_ENABLED
- KEY_DOWN
- KEY_UP
- K_0
- K_1
- K_2
- K_3
- K_4
- K_5
- K_6
- K_7
- K_8
- K_9
- K_ALT
- K_BACKSPACE
- K_CTRL
- K_DOWN
- K_ENTER
- K_ESC
- K_KP1
- K_KP2
- K_KP3
- K_KP4
- K_KP5
- K_KP6
- K_KP7
- K_KP8
- K_KP9
- K_LEFT
- K_RIGHT
- K_SHIFT
- K_SPACE
- K_TAB
- K_UP
- K_a
- K_b
- K_c
- K_d
- K_e
- K_f
- K_g
- K_h
- K_i
- K_j
- K_k
- K_l
- K_m
- K_n
- K_o
- K_p
- K_q
- K_r
- K_s
- K_t
- K_u
- K_v
- K_w
- K_x
- K_y
- K_z
- MOUSE_DOWN
- MOUSE_MOTION
- MOUSE_UP
- MOUSE_WHEEL
- NOEVENT
- NUMEVENTS
- QUIT
- USEREVENT
- _CALLBACK
Event ()
Holds all information about an event.
Event.prototype.button
the number of the mousebutton pressed
Event.prototype.key
key the keyCode of the key. compare with gamejs.event.Ka, gamejs.event.Kb,...
Event.prototype.pos
pos the position of the event for mouse events
Event.prototype.rel
relative movement for a mousemove event
Event.prototype.type
The type of the event. e.g., gamejs.event.QUIT, KEYDOWN, MOUSEUP.
K_UP
Example
gamejs.onEvent(function(event) {
if (event.type === gamejs.event.MOUSE_UP) {
gamejs.log(event.pos, event.button);
} else if (event.type === gamejs.event.KEY_UP) {
gamejs.log(event.key);
}
});