tutorial:keybinds
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tutorial:keybinds [2021/02/28 17:23] – Fixed a minor formatting issue sailkite | tutorial:keybinds [2025/10/22 16:50] (current) – revert that codeblock cassiancc | ||
|---|---|---|---|
| Line 9: | Line 9: | ||
| Adding a key-bind is easy. You'll need to: | Adding a key-bind is easy. You'll need to: | ||
| * open or create a Client [[documentation: | * open or create a Client [[documentation: | ||
| + | * create a Keybinding.Category object | ||
| * create a KeyBinding object | * create a KeyBinding object | ||
| * react to the key being pressed | * react to the key being pressed | ||
| - | See [[https:// | + | See [[https:// |
| ==== Preparing an Entrypoint ==== | ==== Preparing an Entrypoint ==== | ||
| Line 41: | Line 42: | ||
| ==== Creating your Keybind ==== | ==== Creating your Keybind ==== | ||
| - | Declare | + | Declare these in an area of your preference: |
| <code java> | <code java> | ||
| private static KeyBinding keyBinding; | private static KeyBinding keyBinding; | ||
| + | private static final KeyBinding.Category CATEGORY = KeyBinding.Category.create(Identifier.of(" | ||
| </ | </ | ||
| - | FabricKeyBinding | + | KeyBindingHelper |
| <code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
| Line 54: | Line 56: | ||
| InputUtil.Type.KEYSYM, | InputUtil.Type.KEYSYM, | ||
| GLFW.GLFW_KEY_R, | GLFW.GLFW_KEY_R, | ||
| - | | + | |
| + | | ||
| )); | )); | ||
| </ | </ | ||
| - | If you want a sticky key, add '' | + | On versions older than 1.21.9, |
| + | |||
| + | Sticky keys can also be created with '' | ||
| | | ||
| '' | '' | ||
| Line 64: | Line 69: | ||
| ==== Responding to your Keybind ==== | ==== Responding to your Keybind ==== | ||
| - | The code here will print "Key 1 was pressed!" | + | The code here will print "Key 1 was pressed!" |
| + | |||
| + | For versions since 1.19: | ||
| + | <code java> | ||
| + | |||
| + | ClientTickEvents.END_CLIENT_TICK.register(client -> { | ||
| + | while (keyBinding.wasPressed()) { | ||
| + | client.player.sendMessage(Text.literal(" | ||
| + | } | ||
| + | }); | ||
| + | </ | ||
| + | |||
| + | For versions below 1.19: | ||
| <code java> | <code java> | ||
| Line 75: | Line 92: | ||
| </ | </ | ||
| | | ||
| - | Keep note that this is entirely client-side. To have the server respond to a keybind, you'll need to send a custom packet and have the server handle it separately. | + | |
tutorial/keybinds.1614533009.txt.gz · Last modified: 2021/02/28 17:23 by sailkite