wolfhacklua API 1.1 Forum

Input

Three ways to get input#

NeedUsePermission
Let the user choose a key in your settingsui.keybind(id, label, default_vk)none
Know whether a key or mouse button is down right nowinput.key_down(vk)input
Pointer position in the overlayinput.mouse()input
Click, hover and keys inside your own widget or canvasthe w / c table passed to your callbacknone

input.* reports state only (is it down now); there is no history and no way to send keys or clicks. It reports nothing useful while neither the game nor the overlay menu has the focus.

Key codes#

Keys are Windows virtual-key codes (integers). The common ones:

KeyCodeKeyCode
Left mouse0x010-90x30-0x39
Right mouse0x02A-Z0x41-0x5A (A = 0x41)
Middle mouse0x04F1-F120x70-0x7B
Mouse button 4 / 50x05 / 0x06Left, up, right, down arrows0x25, 0x26, 0x27, 0x28
Backspace0x08Insert / Delete0x2D / 0x2E
Tab0x09Home / End0x24 / 0x23
Enter0x0DPage up / down0x21 / 0x22
Shift / Ctrl / Alt0x10 / 0x11 / 0x12Space0x20
Escape0x1BLeft Shift / Left Ctrl0xA0 / 0xA2

Detecting a press (not just "held")#

input.key_down is true for as long as the key is held. To react once per press, remember the previous state:

lua
-- manifest: "permissions": ["input"]
local key = 0x46          -- F
local was = false

events.on("frame", function()
  local down = input.key_down(key)
  if down and not was then
    log.info("F pressed")
  end
  was = down
end)

A user-chosen key#

Combine the two: let the user pick the key, then poll it.

lua
local show = false
local was = false

ui.tab("Panel", function()
  ui.card("Key", function()
    ui.keybind("toggle_key", "Toggle key", 0)       -- saved under "toggle_key"
  end)
end)

events.on("frame", function()
  local k = store.get("toggle_key", 0)
  if k ~= 0 then
    local down = input.key_down(k)
    if down and not was then show = not show end
    was = down
  end
end)

ui.keybind returns the key code (0 means none).

Mouse in your own interface#

  • A widget with interactive = true receives w.mouse_x, w.mouse_y, w.hovered, w.down and w.clicked, in widget coordinates, only while the menu is open. With the menu closed the overlay lets the mouse through to the game, so buttons in a widget cannot be clicked then.
  • A ui.canvas callback receives c.mouse_x, c.mouse_y, c.hovered, c.down, c.clicked, c.released, c.right_clicked, c.wheel, and c.key_down(name) / c.key_pressed(name) for the keys a-z, 0-9, left, right, up, down, space, enter, escape, shift, ctrl, tab.

What is not available#

There are no key-press events (only polling), no text-input capture outside your own controls, and no way to send input to the game. See the gaps page.

API 1.1 · source docs-src/pages/guide/input.md