new InputManager(isCaseSensitiveopt)
Manage user inputs with a poll system (https://en.wikipedia.org/wiki/Polling_(computer_science))
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
isCaseSensitive | boolean | <optional> | false | true so that the inputs are case sensitive |
- Source
Classes
Members
commandsBuffer :Object.<string, boolean>
avoid a command to be computed two times if multiple keys are attach to it
- Object.<string, boolean>
- Source
element :HTMLElement
element catching mouse event
- HTMLElement
- Source
isCaseSensitive :boolean
true so that the inputs are case sensitive
- boolean
- Source
keyCommands :CommandCallback
register a callback associated to a key event
- Source
keyMap :Object.<string, boolean>
register if a key is pressed or not
- Object.<string, boolean>
- Source
keyMapKeyDown :Array.<string>
register if a key state is down
- Array.<string>
- Source
keyMapKeyUp :Array.<string>
register if a key state is up
- Array.<string>
- Source
listeners :Array.<{element:HTMLElement, id:string, cb:EventCallback, listener:EventCallback}>
register listeners to dispose them
- Array.<{element:HTMLElement, id:string, cb:EventCallback, listener:EventCallback}>
- Source
mouseCommands :Object.<string, Object.<string, function(MouseState): Command>>
register callback associated to an event + command id
- Object.<string, Object.<string, function(MouseState): Command>>
- Source
mouseState :MouseState
store state of the mouse
- Source
pause :boolean
if true EventCallback
and CommandCallback
are not called
- boolean
- Source
Methods
addKeyCommand(commandID, keys, cb)
Add a command for severals keys
Name | Type | Description |
---|---|---|
commandID | string | command id |
keys | Array.<string> | keys id assigned |
cb | function | callback called |
- Source
addKeyInput(key, eventID, cb)
Register a callback for a particular key and event
Name | Type | Description |
---|---|---|
key | string | | id of the key if null every key trigger the event |
eventID | string | id of the event (keyup, keydown) |
cb | EventCallback | callback called for this event |
- Source
addMouseCommand(commandID, eventID, cb)
Add a command for mouse
Name | Type | Description |
---|---|---|
commandID | string | id of the command |
eventID | string | id of the mouse to listen to |
cb | function | callback called at event |
- Source
addMouseInput(element, eventID, cb)
Register a callback for a particular mouse event
Name | Type | Description |
---|---|---|
element | HTMLElement | element listened |
eventID | string | id of the event (mousedown, mouseup, mousemove) |
cb | EventCallback | callback called for this event |
- Source
computeCommands() → {Array.<Command>}
Compute Commands with the last state stored of keys and mouse
- Source
- commands computed
- Type:
- Array.<Command>
controlSensitivity(key) → {string}
Converts a key to lowercase if case sensitivity is not required.
Name | Type | Description |
---|---|---|
key | string | keyboard input |
- Source
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
- Source
getElement() → {HTMLElement}
- Source
- input manager element
- Type:
- HTMLElement
getPointerLock() → {boolean}
- Source
- 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
- Source
isKeyALetter(key) → {boolean}
Name | Type | Description |
---|---|---|
key | string | keyboard input |
- Source
- returns true if the key is a letter
- Type:
- boolean
isKeyDown(key) → {boolean}
Name | Type | Description |
---|---|---|
key | string | key id |
- Source
- true if the key state is down
- Type:
- boolean
isKeyUp(key) → {boolean}
Name | Type | Description |
---|---|---|
key | string | key id |
- Source
- 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
Name | Type | Description |
---|---|---|
key | string | key id |
- Source
- 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
Name | Type | Description |
---|---|---|
keys | Array.<string> | ids of the key to listen to |
- Source
removeInputListener(cb)
Remove event listener with the callback used to register it
Name | Type | Description |
---|---|---|
cb | EventCallback | listener pass at the registration |
- Source
removeKeyCommand(commandID, keys)
Dispose a command associated to keys
Name | Type | Description |
---|---|---|
commandID | string | id command |
keys | Array.<string> | keys id |
- Source
removeMouseCommand(commandID, eventID)
Name | Type | Description |
---|---|---|
commandID | string | command id |
eventID | string | mouse event id |
- Source
setPause(pause)
Name | Type | Description |
---|---|---|
pause | boolean | new inputmanager pause value |
- Source
setPointerLock(value)
If value is true pointerLock mode is activated else it's exited
Name | Type | Description |
---|---|---|
value | boolean | new pointerlock value |
- Source
startListening(element)
Start listening
Name | Type | Description |
---|---|---|
element | HTMLElement | element listened by mouse |
- Source