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);
       }
    });



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_0


K_1


K_2


K_3


K_4


K_5


K_6


K_7


K_8


K_9






















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);
       }
    });

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