Skip to content

Keybinds and input

keybinds.bind("heal", { name: "Heal", chord: "ctrl+h" }, () => { ... });

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 Ctrl, Shift or Alt. The buttons are named after an Xbox pad: gamepad_a, gamepad_b, gamepad_x, gamepad_y, gamepad_left_shoulder, gamepad_right_shoulder, gamepad_left_trigger, gamepad_right_trigger, gamepad_dpad_up and so on, gamepad_start, gamepad_back, gamepad_left_stick and gamepad_right_stick.

input.isDown takes a key named like in a chord, so "f8", "a", "left_shift", "gamepad_a" or "ctrl" for either side, or a mouse button like "mouse_left". input.mousePos() is [x, y] in the game window.

import { input } from "wraith";
if (input.isDown("shift") && input.isDown("mouse_right")) aim(input.mousePos());

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.

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. overlay.showCursor only draws the cursor, so take the mouse too if clicks shouldn’t reach the game.

import { overlay } from "wraith";
overlay.takeInput("mouse", true);
overlay.showCursor(true);
// ...
overlay.takeInput("mouse", false);
overlay.showCursor(false);

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