Skip to content

Keybinds and input

_ = try ctx.keybind("heal", .{ .name = "Heal", .chord = .{ .key = .h, .mods = .{ .ctrl = true } } }, self, onHeal);

Players can rebind them in the overlay. The id is what their choice is saved under, so keep it stable.

A controller button works too, like .gamepad_back or .gamepad_y, without modifiers. The buttons are named after an Xbox pad: gamepad_a, gamepad_b, gamepad_x, gamepad_y, the shoulders, triggers, d-pad, gamepad_start, gamepad_back and the two stick clicks.

sdk.input.parse takes a key named like in a chord, so "f8", "left_shift", "gamepad_a" or "ctrl" for either side, or a mouse button like "mouse_left".

if (sdk.input.isDown(.{ .mod = .shift }) and sdk.input.isButtonDown(.right)) {
if (sdk.input.mousePos()) |p| aim(p.x, p.y);
}

Keys and the mouse go by the game window’s messages, so nothing’s down while another window has focus. Controllers are read on their own and don’t need focus. Any thread.

sdk.overlay.takeInput hides the keyboard, the mouse or controllers from the game, until you give it back or the plugin stops. A taken keyboard or controller also moves around the overlay’s windows. sdk.overlay.showCursor only draws the cursor, so take the mouse too if clicks shouldn’t reach the game.

sdk.overlay.takeInput(.mouse, true);
sdk.overlay.showCursor(true);
// ...
sdk.overlay.takeInput(.mouse, false);
sdk.overlay.showCursor(false);

sdk.overlay.inputTaken(.keyboard) says whether anyone has it, like the user being in the overlay. Players can stop controllers being taken at all in Wraith’s settings.

Made with ♥ by Asgard