OPX//77
opx_lib

Lib.Input

Last updated on

Declare rebindable key actions and read the keyboard and cursor.

Permission input.actions. Up to 64 actions per resource (Input.LIMIT, enforced by the engine).

Lib.Input.On

Declares a rebindable action, shown in the game's key bindings. Passing released makes it a hold.

Lib.Input.On(id, label, key, pressed, released)

Parameters

  • id: string
    • Unique in your resource; up to 64 bytes of [A-Za-z0-9_.:-].
  • label: string
    • Up to 96 bytes.
  • key: string — e.g. 'F6', 'CAPSLOCK'
  • pressed: function
  • released?: function

Returns

  • Result — the effective key (the saved rebind, else the default); errors invalid_id, invalid_label, invalid_key, invalid_handler
Example
Lib.Input.On('my_shop.open', 'Open shop', 'F6', function() openShop() end)

Lib.Input.Off

Removes an action you declared.

Lib.Input.Off(id)

Parameters

  • id: string

Returns

  • Result — error invalid_id

Lib.Input.Block

Blocks or unblocks one of the game's own actions.

Lib.Input.Block(action, blocked)

Parameters

  • action: string
  • blocked: boolean

Returns

  • Result — error invalid_action

Lib.Input.IsCaptured

Whether another surface holds the keyboard. A read that raises answers true.

Lib.Input.IsCaptured()

Returns

  • boolean

Lib.Input.IsDown

Whether a key is held down now.

Lib.Input.IsDown(key)

Parameters

  • key: string

Returns

  • boolean

Lib.Input.Cursor

The mouse cursor.

Lib.Input.Cursor()

Returns

  • table? — at least inBounds and captured; nil when it cannot be read

Lib.Input.KeyFor

The key one of your actions answers to now, rebinds included.

Lib.Input.KeyFor(action)

Parameters

  • action: string — the id it was declared under

Returns

  • string?
Example
Lib.Notify.Show(('Press %s to open the shop'):format(Lib.Input.KeyFor('my_shop.open') or 'F6'))

Lib.Input.Mappings

Every key mapping on the client, all resources.

Lib.Input.Mappings()

Returns

  • { resource, id, key }[]?, string? — the list, or nil and why

On this page