Skip to content

Instantly share code, notes, and snippets.

@Vendicated
Last active June 20, 2023 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vendicated/ba67a69c9e694040df1d558ac2955317 to your computer and use it in GitHub Desktop.
Save Vendicated/ba67a69c9e694040df1d558ac2955317 to your computer and use it in GitHub Desktop.
DiscordNative global keybinds

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment