This is a script for Rebar that manages hotkeys with long-press detection.
- Binds hotkeys to callback functions.
- Detects long-presses for hotkeys with a configurable timeout.
This script requires the Rebar framework for alt:V.
-
Clone the repository in your
pluginsfolder:git clone https://github.com/nightowl07/rebar-hotkeys src/plugins/hotkeys
-
Get the API
await alt.Utils.waitFor(() => useClientApi().isReady('hotkey-api')); const hotkeyApi = useClientApi().get('hotkey-api')
-
Use the
hotkeyApifunction to get access to theaddHotkeyandremoveHotkeyfunctions:// Example usage hotkeyApi.addHotkey(84, (isLongPress) => { if (isLongPress) { console.log('T key long-pressed!'); } else { console.log('T key pressed!'); } });
addHotkey(key, callback): Binds a hotkey identified by its key code to a callback function. The callback function receives a boolean argument indicating whether the key was held long enough to be considered a long-press.removeHotkey(key): Removes the hotkey binding for the specified key code.
longPressTimeout: This variable defines the time (in milliseconds) after which a key press is considered a long-press. You can modify this value in the constructor of theHotKeyManagerclass.