Class me.input
Defined in: <build/melonJS-0.9.3.js>.
| Constructor Attributes | Constructor Name and Description |
|---|---|
|
me.input()
There is no constructor function for me.input.
|
| Field Attributes | Field Name and Description |
|---|---|
|
Accelerometer information
properties : x, y, z |
|
|
list of mappable keys :
LEFT, UP, RIGHT, DOWN, ENTER, SHIFT, CTRL, ALT, PAUSE, ESC, ESCAPE, [0.
|
|
|
Mouse information
properties : pos (me.Vector2d) : pointer position LEFT : constant for left button MIDDLE : constant for middle button RIGHT : constant for right button |
|
|
Array of object containing touch information
properties : x : x position of the touch event in the canvas y : y position of the touch event in the canvas id : unique finger identifier |
| Method Attributes | Method Name and Description |
|---|---|
|
bindKey(keycode, action, lock)
associate a user defined action to a keycode
|
|
|
bindMouse(button, keyCode)
Associate a mouse (button) action to a keycode
Left button – 0
Middle button – 1
Right button – 2
|
|
|
bindTouch(keyCode)
Associate a touch action to a keycode
|
|
|
isKeyPressed(action)
return the key press status of the specified action
|
|
|
keyStatus(action)
return the key status of the specified action
|
|
|
registerMouseEvent(eventType, rect, callback)
register on a mouse event for a given region
note : on a touch enabled device mouse event will automatically be converted to touch event
|
|
|
releaseMouseEvent(eventType, region)
release the previously registered mouse event callback
note : on a touch enabled device mouse event will automatically be converted to touch event
|
|
|
triggerKeyEvent(keycode, true)
trigger the specified key (simulated) event
|
|
|
unbindKey(keycode)
unbind the defined keycode
|
|
|
unbindMouse(button)
unbind the defined keycode
|
|
|
unbind the defined touch binding
|
|
|
unwatch Accelerometor event
|
|
|
watch Accelerator event
|
Field Detail
accel
Accelerometer information
properties : x, y, z
properties : x, y, z
KEY
list of mappable keys :
LEFT, UP, RIGHT, DOWN, ENTER, SHIFT, CTRL, ALT, PAUSE, ESC, ESCAPE, [0..9], [A..Z]
mouse
Mouse information
properties :
pos (me.Vector2d) : pointer position
LEFT : constant for left button
MIDDLE : constant for middle button
RIGHT : constant for right button
properties :
pos (me.Vector2d) : pointer position
LEFT : constant for left button
MIDDLE : constant for middle button
RIGHT : constant for right button
touches
Array of object containing touch information
properties :
x : x position of the touch event in the canvas
y : y position of the touch event in the canvas
id : unique finger identifier
properties :
x : x position of the touch event in the canvas
y : y position of the touch event in the canvas
id : unique finger identifier
Method Detail
bindKey(keycode, action, lock)
associate a user defined action to a keycode
// enable the keyboard me.input.bindKey(me.input.KEY.LEFT, "left"); me.input.bindKey(me.input.KEY.RIGHT, "right"); me.input.bindKey(me.input.KEY.X, "jump", true);
- Parameters:
- {me.input#KEY} keycode
- {String} action
- user defined corresponding action
- {boolean} lock
- cancel the keypress event once read
bindMouse(button, keyCode)
Associate a mouse (button) action to a keycode
Left button – 0
Middle button – 1
Right button – 2
// enable the keyboard me.input.bindKey(me.input.KEY.X, "shoot"); // map the left button click on the X key me.input.bindMouse(me.input.mouse.LEFT, me.input.KEY.X);
- Parameters:
- {Integer} button
- (accordingly to W3C values : 0,1,2 for left, middle and right buttons)
- {me.input#KEY} keyCode
bindTouch(keyCode)
Associate a touch action to a keycode
// enable the keyboard me.input.bindKey(me.input.KEY.X, "shoot"); // map the touch event on the X key me.input.bindTouch(me.input.KEY.X);
- Parameters:
- {me.input#KEY} keyCode
{boolean}
isKeyPressed(action)
return the key press status of the specified action
if (me.input.isKeyPressed('left'))
{
//do something
}
else if (me.input.isKeyPressed('right'))
{
//do something else...
}
- Parameters:
- {String} action
- user defined corresponding action
- Returns:
- {boolean} true if pressed
{boolean}
keyStatus(action)
return the key status of the specified action
- Parameters:
- {String} action
- user defined corresponding action
- Returns:
- {boolean} down (true) or up(false)
registerMouseEvent(eventType, rect, callback)
register on a mouse event for a given region
note : on a touch enabled device mouse event will automatically be converted to touch event
// register on the 'mousemove' event
me.input.registerMouseEvent('mousemove', this.collisionBox, this.mouseMove.bind(this));
- Parameters:
- {String} eventType
- ('mousemove','mousedown','mouseup','mousewheel','touchstart','touchmove','touchend')
- {me.Rect} rect
- (object must inherits from me.Rect)
- {Function} callback
releaseMouseEvent(eventType, region)
release the previously registered mouse event callback
note : on a touch enabled device mouse event will automatically be converted to touch event
// release the registered callback on the 'mousemove' event
me.input.releaseMouseEvent('mousemove', this.collisionBox);
- Parameters:
- {String} eventType
- ('mousemove','mousedown','mouseup','mousewheel','touchstart','touchmove','touchend')
- {me.Rect} region
triggerKeyEvent(keycode, true)
trigger the specified key (simulated) event
// trigger a key press me.input.triggerKeyEvent(me.input.KEY.LEFT, true);
- Parameters:
- {me.input#KEY} keycode
- {boolean} true
- to trigger a key press, or false for key release
unbindKey(keycode)
unbind the defined keycode
me.input.unbindKey(me.input.KEY.LEFT);
- Parameters:
- {me.input#KEY} keycode
unbindMouse(button)
unbind the defined keycode
me.input.unbindMouse(me.input.mouse.LEFT);
- Parameters:
- {Integer} button
- (accordingly to W3C values : 0,1,2 for left, middle and right buttons)
unbindTouch()
unbind the defined touch binding
me.input.unbindTouch();
unwatchAccelerometer()
unwatch Accelerometor event
{boolean}
watchAccelerometer()
watch Accelerator event
- Returns:
- {boolean} false if not supported by the device