InputManager

new InputManager(isCaseSensitiveopt)

Manage user inputs with a poll system (https://en.wikipedia.org/wiki/Polling_(computer_science))

Parameters:
NameTypeAttributesDefaultDescription
isCaseSensitiveboolean<optional>
false

true so that the inputs are case sensitive

Classes

InputManager

Members

commandsBuffer :Object.<string, boolean>

avoid a command to be computed two times if multiple keys are attach to it

Type:
  • Object.<string, boolean>

element :HTMLElement

element catching mouse event

Type:
  • HTMLElement

isCaseSensitive :boolean

true so that the inputs are case sensitive

Type:
  • boolean

keyCommands :CommandCallback

register a callback associated to a key event

keyMap :Object.<string, boolean>

register if a key is pressed or not

Type:
  • Object.<string, boolean>

keyMapKeyDown :Array.<string>

register if a key state is down

Type:
  • Array.<string>

keyMapKeyUp :Array.<string>

register if a key state is up

Type:
  • Array.<string>

listeners :Array.<{element:HTMLElement, id:string, cb:EventCallback, listener:EventCallback}>

register listeners to dispose them

Type:
  • Array.<{element:HTMLElement, id:string, cb:EventCallback, listener:EventCallback}>

mouseCommands :Object.<string, Object.<string, function(MouseState): Command>>

register callback associated to an event + command id

Type:
  • Object.<string, Object.<string, function(MouseState): Command>>

mouseState :MouseState

store state of the mouse

pause :boolean

if true EventCallback and CommandCallback are not called

Type:
  • boolean

Methods

addKeyCommand(commandID, keys, cb)

Add a command for severals keys

Parameters:
NameTypeDescription
commandIDstring

command id

keysArray.<string>

keys id assigned

cbfunction

callback called

addKeyInput(key, eventID, cb)

Register a callback for a particular key and event

Parameters:
NameTypeDescription
keystring | null

id of the key if null every key trigger the event

eventIDstring

id of the event (keyup, keydown)

cbEventCallback

callback called for this event

addMouseCommand(commandID, eventID, cb)

Add a command for mouse

Parameters:
NameTypeDescription
commandIDstring

id of the command

eventIDstring

id of the mouse to listen to

cbfunction

callback called at event

addMouseInput(element, eventID, cb)

Register a callback for a particular mouse event

Parameters:
NameTypeDescription
elementHTMLElement

element listened

eventIDstring

id of the event (mousedown, mouseup, mousemove)

cbEventCallback

callback called for this event

computeCommands() → {Array.<Command>}

Compute Commands with the last state stored of keys and mouse

Returns:
  • commands computed
Type: 
Array.<Command>

controlSensitivity(key) → {string}

Converts a key to lowercase if case sensitivity is not required.

Parameters:
NameTypeDescription
keystring

keyboard input

Returns:

the input key in lowercase if the isCaseSensitive is false and the input key is a letter. Returns the base key otherwise.

Type: 
string

dispose()

Remove listeners and reset variables

getElement() → {HTMLElement}

Returns:
  • input manager element
Type: 
HTMLElement

getPointerLock() → {boolean}

Returns:
  • input manager pointer lock value
Type: 
boolean

initPointerLock()

Initialize pointer lock management On keypress keyup and click event try to request pointer lock on this.element if this.pointerLock is true

isKeyALetter(key) → {boolean}

Parameters:
NameTypeDescription
keystring

keyboard input

Returns:
  • returns true if the key is a letter
Type: 
boolean

isKeyDown(key) → {boolean}

Parameters:
NameTypeDescription
keystring

key id

Returns:
  • true if the key state is down
Type: 
boolean

isKeyUp(key) → {boolean}

Parameters:
NameTypeDescription
keystring

key id

Returns:
  • true if the key state is up
Type: 
boolean

isPressed(key) → {boolean}

Return true if the key is pressed, dont forget to listenKeys if no addKeyCommand has been used for this key

Parameters:
NameTypeDescription
keystring

key id

Returns:
  • true if pressed, false otherwise
Type: 
boolean

listenKeys(keys)

Used this if a key has not been register in addKeyCommand and you need to know if it's isPressed

Parameters:
NameTypeDescription
keysArray.<string>

ids of the key to listen to

removeInputListener(cb)

Remove event listener with the callback used to register it

Parameters:
NameTypeDescription
cbEventCallback

listener pass at the registration

removeKeyCommand(commandID, keys)

Dispose a command associated to keys

Parameters:
NameTypeDescription
commandIDstring

id command

keysArray.<string>

keys id

removeMouseCommand(commandID, eventID)

Parameters:
NameTypeDescription
commandIDstring

command id

eventIDstring

mouse event id MOUSE_STATE_EVENTS

setPause(pause)

Parameters:
NameTypeDescription
pauseboolean

new inputmanager pause value

setPointerLock(value)

If value is true pointerLock mode is activated else it's exited

Parameters:
NameTypeDescription
valueboolean

new pointerlock value

startListening(element)

Start listening

Parameters:
NameTypeDescription
elementHTMLElement

element listened by mouse