IMIsle Modkit
Pages in this area

keys

Client

Key handlers for client scripts. The client mod reads the keyboard state with GetAsyncKeyState each time the client scripts run, about five times per second. Handlers fire only while the game window is in the foreground.

Because of the 200 ms sampling a very short tap can be missed, and the handler runs up to 200 ms after the key moved. It is fine for menus and toggles. It is not good enough for anything that needs fast reactions.

The keys are read next to the game. The game still sees the same key. If you bind E, the game's own action on E happens as well.

Key names

Names Keys
A to Z, 0 to 9 letters and digits, case does not matter
F1 to F24 function keys
SPACE, ENTER, TAB, ESC
SHIFT, CTRL, ALT
UP, DOWN, LEFT, RIGHT arrow keys
INSERT, DELETE, HOME, END, PAGEUP, PAGEDOWN
NUMPAD0 to NUMPAD9
MOUSE3, MOUSE4, MOUSE5 middle button and the two side buttons

An unknown name raises a Lua error.

modkit.keys.on

modkit.keys.on(key, fn)

Parameter Type Description
key string key name
fn function fn(down). down is true when the key went down and false when it came up.

Returns: binding id (integer).

local shopOpen = false
modkit.keys.on("F5", function(down)
  if not down then return end
  shopOpen = not shopOpen
  modkit.events.call("shop:toggle", shopOpen)
end)

modkit.keys.off

modkit.keys.off(id)

Removes a binding.

Parameter Type Description
id integer id from modkit.keys.on. Unknown ids are ignored.

Returns: nothing.

local id = modkit.keys.on("F7", function(down) print(down) end)
modkit.keys.off(id)

modkit.keys.isDown

modkit.keys.isDown(key)

Parameter Type Description
key string key name

Returns: true when the key is held right now and the game window is in the foreground.

modkit.keys.on("F5", function(down)
  if down and modkit.keys.isDown("SHIFT") then print("shift + F5") end
end)