Skip to content

Keys and hotkeys ​

Everything a key or mouse button does is an action with a name (worker.idle, camera.left, card.move). Actions come with default keys, the player can rebind them on the Keys screen of the pause menu, and your game adds its own.

Quick start ​

ts
input: {
	keys: {
		abilities: ['Q', 'W', 'E', 'R'], spells: ['D', 'F'], shop: 'P', // a hero's keys
		actions: {
			add: [{ id: 'td.nextWave', label: 'Call the next wave now', group: 'Tower defense', default: ['N'], run: (client) => client.runAction('nextWave') }],
			hide: ['chat.all', 'group.*'], // client actions you don't want
			change: { 'worker.idle': { default: ['Backslash'], label: 'Next idle builder' } }
		}
	}
}

N now calls the next wave, chat to all and control groups are gone, and the idle-worker key moved. The player can rebind all of it.

Common tasks ​

Read or set a binding in code ​

ts
client.keys.bindings('worker.idle') // [{ code: 'F8' }]
client.keys.key('worker.idle') // 'F8', as the player's keyboard shows it
client.keys.bind('worker.idle', ['Ctrl+KeyI', 'Backslash'])
client.keys.reset('worker.idle'); client.keys.reset()

React to an action ​

ts
client.keys.on('td.nextWave', (press) => { /* … */ }) // return true to take it from the action
client.keys.press('worker.idle') // do it, as its key would: for a button of your own
client.keys.held('camera.follow')
client.keys.is('order', event) // is this key or pointer event the action?

Put two actions on one key ​

Give them different whens ('hero', 'card', or a word of your own), or have run return false when it is not its turn: the next action on the key is asked. That is how 1 is a hero's item with a hero selected and control group 1 without.

Show a key in your own tooltip ​

client.keys.key(id) gives the key as the player's keyboard shows it.

Reference ​

Keys are places, not letters ​

A binding is a key's place on the keyboard (KeyboardEvent.code: KeyQ is right of Tab) plus modifiers, or a mouse button: { code: 'KeyQ', ctrl: true }, { button: 2 }, or in words 'Ctrl+KeyQ', 'F8', 'Alt+MouseLeft'. A letter alone ('Q') is the key that types it on QWERTY, which is how a definition's hotkey and GameView.hud.card are read. So a French keyboard moves no key, and every key is shown as the character that keyboard types there.

An action ​

FieldWhat
idits name
labelwords on the Keys screen
groupheading it is listed under
defaultkeys it comes with
run(client, press) => …; returning false passes the key to the next action
hintmore words for the Keys screen
heldit lasts while the key is down (run again on release, press.down); a mouse button pressed while Alt or ⌘ is down as one (bars.peek) is the button alone, unless something is on it with that key
pointerit goes on a mouse button, not a key
shiftwhat Shift means with it, in words; Shift is then not part of its keys (press.shift)
whenwhen it counts ('hero', 'card', your own word)
familyseveral actions shown as one line (the ten control groups)

The client's actions (clientActions, CAMERA_ACTIONS) ​

GroupActions
cameracamera.left, right, up, down (arrows); camera.turnLeft, turnRight (Q, E with Alt); camera.drag (middle button); camera.follow (Space, held); camera.lockHero (Y); camera.lastAlert; camera.save.1–4 (Ctrl or Alt+Shift with F1–F4); camera.recall.1–4 (Shift+F1–F4)
selectionselect (left button); selection.next, previous (Tab); selection.lock; selection.clear; hero.select.1… (F1–F4); worker.idle, worker.idle.all (F8); select.army (Shift+`); bars.peek (Alt)
ordersorder (right button); order.circle (Ctrl+right: the same order, the group in a circle); ping (Alt+left); ping.wheel (Ctrl+left, held); one per card command: card.move, card.attack, card.build-menu…
heroeshero.ability.1…, hero.spell.1…, hero.shop, hero.learn.1… (Ctrl with the ability's key), hero.slot.1–6
groupsgroup.select.N, group.add.N, group.assign.N, group.forget.N, for 1–9 and 0
interfaceback (Esc), menu (F10), objectives (F9), log (Alt+L), legend, debug.panel (Alt+Shift+D), layout.edit (Alt+Shift+L), dialog.next, chat.allies, chat.all (Enter)

client.saveView(n) and client.recallView(n) save and recall camera views from code.

Shift always queues an order and adds to a selection, and the wheel always zooms: those are not actions.

client.keys (an Actions) ​

bindings, key, bind, reset, is, held, on, press, sharing(id) (other actions on its keys and whether they clash), onChange((kept) => …), kept() (the player's own bindings as plain data). Reads are signals, so watch follows them.

The Keys screen and legend ​

The legend (the part legend) is made from the actions and their current keys (shortcutsOf(client.keys)). The Keys screen is KeysList (@v12-engine/client/app), given any Actions: use it in a menu of your own, or draw your own from client.keys.

Keys in full screen ​

In full screen, where the browser supports it (Chromium's keyboard lock), the game keeps Esc and every key an action uses, so Esc opens your pause menu (held down, it still leaves full screen). GameView.input.lockKeys: false leaves the browser its keys. In code: client.keyboardLock (enabled, locked(), codes(), refresh()).