xhookLua
Game

input

Keyboard and mouse state; keys use Windows virtual-key codes.

Functions

input.is_key_down

input.is_key_down(key) -> boolean
NameTypeDescription
keyinteger | stringCode or name, like 0x20 or "SPACE".

Live hardware state of a key.

Returns true while physically held

  • An unknown key name raises an error.
  • False while the game window is not focused.

input.is_key_pressed

input.is_key_pressed(key) -> boolean
NameTypeDescription
keyinteger | stringCode or name.

Edge-triggered: true once when the key goes down.

Returns true once per press

  • Tracked per script: two scripts polling one key both see the press.
  • A tap that starts and ends between two calls is missed.
  • No presses while the game window is not focused.

input.cursor_position

input.cursor_position() -> x, y

Overlay mouse cursor position.

Returns screen pixels

Returns 0, 0 before the overlay initialises.

input.mouse_delta

input.mouse_delta() -> dx, dy

Overlay cursor movement this frame.

Returns pixels moved since last frame

Returns 0, 0 before the overlay initialises.

input.scroll

input.scroll() -> number

Vertical wheel movement this frame.

Returns positive is up, about 1 per notch

input.is_menu_open

input.is_menu_open() -> boolean

Gate clickable widgets on this.

Returns true while the menu is open

input.is_mouse_down

input.is_mouse_down([button = 0]) -> boolean
NameTypeDescription
buttonoptionalinteger0 left, 1 right, 2 middle, 3/4 side. Default 0.

Mouse button state from the overlay.

Returns true while held

Buttons outside 0 to 4 return false.

input.mouse_clicked

input.mouse_clicked([button = 0]) -> boolean
NameTypeDescription
buttonoptionalinteger0 left, 1 right, 2 middle, 3/4 side. Default 0.

Per-frame mouse click edge.

Returns true only on the press frame

Every caller in a frame gets the same answer.

input.set_cursor_hidden

input.set_cursor_hidden(on)
NameTypeDescription
onbooleantrue hides, false shows.

Hides the menu cursor so a script can draw its own.

Expires after about 150 ms, so call it every frame.

input.set_cursor_free

input.set_cursor_free(on)
NameTypeDescription
onbooleanfalse lets go at once.

Free mouse cursor in game while the menu is closed.

  • The view stops turning and clicks do not fire while it is on.
  • Expires after about 150 ms, so call it every frame.

input.set_text_capture

input.set_text_capture(on)
NameTypeDescription
onbooleanfalse lets go at once.

Takes the keyboard for a text field; the game gets no keys.

  • Works only while input.set_cursor_free is on.
  • Expires after about 150 ms, so call it every frame.

input.read_text

input.read_text() -> string

Characters typed since the last call, UTF-8.

  • Control keys come as characters: "\b", "\r", "\27", "\t".
  • Holds 128 characters between calls; the rest is dropped.

input.keys

Key names to codes: A to Z, 0 to 9, F1 to F12, MOUSE1 to MOUSE5, SPACE, SHIFT, CTRL, ALT and more.

Every key argument takes a name or a code, any case: input.is_key_down("f").

input.key_name

input.key_name(key) -> string | nil
NameType
keyinteger

Name of a key code.

input.key_code

input.key_code(key) -> integer
NameType
keystring

Code of a key name; 0 when unknown.

input.menu_bounds

input.menu_bounds() -> x, y, w, h

Screen rectangle of the cheat menu.

Returns nil while it is closed

input.is_cursor_visible

input.is_cursor_visible() -> boolean

The menu or the game's own UI (console, buy menu, pause menu) shows a cursor.

input.is_focused

input.is_focused() -> boolean

True while the game window is in the foreground.

input ยท Lua API ยท xhook