you can use Discord's api for this:
DiscordNative.nativeModules.requireModule("discord_utils").inputEventRegister(
1337,
[
[0, 0xA2],
[0, 0x42]
],
isDown => console.log(isDown),
{
blurred: true,
focused: true,
keydown: true,
keyup: true
}
)
- the first argument is a numeric id that you can later use to unregister the handler again
- the second argument is an array of keycodes. I'm not sure what the first number means, you can just pass 0 for it. The second number is the virtual keycode for the specific key. These differ per platform but Discord has keycode mappings for each platform. You can find all 3 of these mappings via
getModuleByProps("ctrl")
In my example, i am on Windows and use 0xA2 (left control) + 0x42 (B) - the third argument is either the callback or the literal string "UNASSIGNED". It will be fired whenever the key is pressed or released, and gives you the boolean state as argument
- the final argument is an options object:
- blurred: keybind active when discord not focused
- focused: keybind active when discord focused
- keydown: fire callback for key down (isDown = true)
- keyup: fire callback for key up (isDown = false)
Obtain keycodes for each platform:
const WindowsMappings = getModule(m => m.ctrl === 0xa2)
const LinuxMappings = getModule(m => m.ctrl === 0x25)
const MacMappings = getModule(m => m.ctrl === 0xe0)
To unregister:
DiscordNative.nativeModules.requireModule("discord_utils").inputEventUnregister(1337)