KeyBind
com.jsmacrosce.jsmacros.client.api.library.impl.FKeyBind
Gets and changes key and keybind states through the script global KeyBind.
Key names identify inputs (for example, key.keyboard.w); keybind names identify actions (for example, key.forward). key methods take key names, while keyBind methods and setKeyBind(String, String) take keybind names. State-setting calls are ignored while a screen is open. Press calls mark the state down and register a click; release calls mark it up. Use the matching release call after a press to avoid leaving a key held.
js
// Look up the current key assigned to forward.
const binds = KeyBind.getKeyBindings();
Chat.log(`forward is on ${binds.get("key.forward")}`);
// Hold the forward action briefly, regardless of its assigned key.
KeyBind.pressKey("key.keyboard.w");
Client.waitTick(2);
// and releasing marks it up again
KeyBind.releaseKey("key.keyboard.w");
// the same thing by keybind name, which is what to use when the binding might be
// on a different key than the default
KeyBind.pressKeyBind("key.forward");
Client.waitTick(2);
KeyBind.releaseKeyBind("key.forward");
// rebind jump to the numpad 0 key, and put it back afterwards
KeyBind.setKeyBind("key.jump", "key.keyboard.numpad.0");
KeyBind.setKeyBind("key.jump", null);
// what is held down at this moment
for (const key of KeyBind.getPressedKeys()) {
Chat.log(`held: ${key}`);
}Accessible in scripts via the global KeyBind variable.
Nested types
Methods
getKeyBindings
getKeyCode
getKeyCode(String keyName): InputConstants.Key#Resolves a serialized key name to Minecraft's key representation. An unrecognized name resolves to the unknown key rather than indicating failure.
Parameters:
keyName: the name of the key, for examplekey.keyboard.w
Returns: the resolved key, or Minecraft's unknown key for an unrecognized name
getPressedKeys
key
Sets the state of the named key, affecting every keybind currently mapped to that key. Setting it down also registers a click. State changes are ignored while a screen is open; an unrecognized name resolves to the unknown key.
Parameters:
keyName: the name of the key, for examplekey.keyboard.wkeyState:trueto mark the key down,falseto mark it up
keyBind
Sets the state of the named keybind, independent of which key it is assigned to. Setting it down also registers a click. Has no effect while a screen is open or if no keybind matches.
Parameters:
keyBind: the name of the keybind, for examplekey.forwardkeyState:trueto mark the keybind down,falseto mark it up
pressKey
pressKeyBind
releaseKey
Marks the named key up and removes it from getPressedKeys(). Has no effect while a screen is open.
Parameters:
keyName: the name of the key to release
releaseKeyBind
Calls keyBind(String, boolean) with keyState set to false. Marks the matching keybind up and removes its name from getPressedKeys(). Does nothing while a screen is open or when no keybind has this name.
Parameters:
keyBind: the name of the keybinding to release
setKeyBind
Reassigns the first keybind with the given name;
null unbinds it. This changes the binding, not its pressed state. An unmatched name has no effect.Parameters:
bind: the name of the keybind, for examplekey.forwardkey: the name of the key to put it on, ornullto unbind it