Violet

Keys

On this page

Provides access to the game keyboard layout. These functions edit the game's key mapping table for the active key preset.

Key codes: Virtual Key Codes Reference

Changes are not saved until you call `save()`

A new bind works on the very next keypress — but it is lost when you change character or relog unless you save. Call core.keys.save() once after a batch of edits.

Mapping Types

Every key slot holds a type and an id. Use core.keys.type.* rather than the raw numbers.

TypeConstantMeaningid is
0EMPTYUnboundignored
1SKILLSkillskill ID
2ITEMConsumable itemitem ID
3FACE_ITEMFace expression itemitem ID
4MENUUI window / menu actionmenu ID (see below)
5ACTIONBasic actionaction ID (see below)
6EMOTEFace expression100-106
7EFFECT_ITEMActive effect itemitem ID
8MACROSkill macromacro index, from 0
9CASH_ITEMCash inventory itemitem ID

Action IDs

Type 5 — the built-in binds (jump, pick up, and friends). These five are the only valid action IDs. Use core.keys.action.*.

IDConstantActionDefault key
50PICK_UPPick up itemZ
51SITSit downX
52ATTACKAttack / regular attackCtrl
53JUMPJumpAlt
54NPC_CHATTalk to NPC / gatherSpace
lua
core.keys.set_action(0x20, core.keys.action.JUMP) -- Space = jump
core.keys.set_action(0x5A, core.keys.action.PICK_UP) -- Z = pick up
core.keys.save()

Emote IDs

Type 6 — the face expressions on the function-key row by default. Valid IDs are 100 through 106.

IDDefault key
100F1
101F2
102F3
103F5
104F6
105F7
106F8

Type 4 — UI windows and menu toggles. Valid IDs are 0-49, 200-206, 300, and 1000-1001; anything else is rejected.

Other IDs inside the valid ranges are accepted but aren't listed here.

IDOpensDefault key
0EquipmentE
1Item InventoryI
2StatS
3SkillK
5World MapW
6MessengerC
7Minimap (toggle)M
8QuestQ
14Menu[
15Quickslot]
16Chat (toggle)'
17GuildG
20Quest Alarm (toggle)L
39Contents GuideU
48Capture Mode—
203Emoticon—

Presets

The game keeps three key presets, numbered 0-2. All the setters operate on whichever preset is currently applied.

Notes on key codes

A virtual-key code is translated to the game's own key-map slot, and that translation is not one-to-one:

  • The right-hand modifiers share a slot with their left-hand twin, so binding RShift / RCtrl / RAlt changes the LShift / LCtrl / LAlt bind.
  • IME keys have no slot at all. Binding one raises an error rather than silently doing nothing.

Functions

core.keys.get(vkey: number) -> {type: number, id: number, index: number}

Available on GMS and CW

Returns the current game key mapping for a keyboard virtual-key code. index is the key-map slot for that key, which is useful when two keys share a slot.

lua
local mapping = core.keys.get(0x41) -- A
core.log(string.format("type=%d id=%d", mapping.type, mapping.id))

core.keys.set(vkey: number, type: number, id: number)

Available on GMS and CW

Sets a game key mapping to any supported type. The id is validated against the type, so an out-of-range action or menu ID raises an error instead of producing a dead key. Use unset() to clear a key.

lua
core.keys.set(0x41, core.keys.type.SKILL, 1001004) -- A = skill
core.keys.set(0x42, core.keys.type.ITEM, 2000000) -- B = item
core.keys.set(0x20, core.keys.type.ACTION, core.keys.action.JUMP) -- Space = jump

core.keys.set_skill(vkey: number, skill_id: number)

Available on GMS and CW

Sets a keyboard key to a skill.

lua
core.keys.set_skill(0x41, 1001004) -- A

core.keys.set_item(vkey: number, item_id: number)

Available on GMS and CW

Sets a keyboard key to an item.

lua
core.keys.set_item(0x42, 2000000) -- B

core.keys.set_action(vkey: number, action_id: number)

Available on GMS and CW

Sets a keyboard key to a basic action such as jump or pick up. See Action IDs.

lua
core.keys.set_action(0x20, core.keys.action.JUMP) -- Space

core.keys.set_menu(vkey: number, menu_id: number)

Available on GMS and CW

Sets a keyboard key to a UI window or menu toggle. See Menu IDs.

lua
core.keys.set_menu(0x49, 1) -- I = Item Inventory

core.keys.set_emote(vkey: number, emote_id: number)

Available on GMS and CW

Sets a keyboard key to a face expression. emote_id must be 100-106.

lua
core.keys.set_emote(0x70, 100) -- F1

core.keys.set_macro(vkey: number, macro_index: number)

Available on GMS and CW

Sets a keyboard key to a skill macro. macro_index starts at 0.

lua
core.keys.set_macro(0x71, 0) -- F2 = first macro

core.keys.unset(vkey: number)

Available on GMS and CW

Clears a keyboard key mapping.


core.keys.save() -> boolean

Available on GMS and CW

Saves the active preset so the changes persist. Returns false when the server has key-map editing locked. Call this once after a batch of edits, not after every one.

lua
core.keys.set_action(0x20, core.keys.action.JUMP)
core.keys.set_action(0x5A, core.keys.action.PICK_UP)
core.keys.save()

core.keys.get_preset() -> number

Available on GMS and CW

Returns the active key preset, 0-2.


core.keys.set_preset(preset: number) -> boolean

Available on GMS and CW

Switches the active key preset. preset must be 0-2. Returns false when the server has key-map editing locked, in which case the game shows its own message.

lua
core.keys.set_preset(1)

core.keys.is_edit_blocked() -> boolean

Available on GMS and CW

Returns true while the server has key-map editing locked. save() and set_preset() both fail in that state.