Skip to content

Commit 93f7ef0

Browse files
authored
fix: change keyCode to action (#667)
* fix: change keyCode to action The int passed to the keyPressed function represents the action instead of the keyCode. The keyCode is inside the keyEvent. The action is 1 for key pressed and 0 for key released. * fix: wrong parameter in NeoForge
1 parent dd8ddff commit 93f7ef0

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

common/src/main/java/dev/architectury/event/events/client/ClientRawInputEvent.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public interface ClientRawInputEvent {
3232
*/
3333
Event<MouseScrolled> MOUSE_SCROLLED = EventFactory.createEventResult();
3434
/**
35-
* @see MouseClicked#mouseClicked(Minecraft, int, int, int)
35+
* @see MouseClicked#mouseClicked(Minecraft, MouseButtonInfo, int)
3636
*/
3737
Event<MouseClicked> MOUSE_CLICKED_PRE = EventFactory.createEventResult();
3838
Event<MouseClicked> MOUSE_CLICKED_POST = EventFactory.createEventResult();
@@ -47,12 +47,12 @@ interface KeyPressed {
4747
* Equivalent to Forge's {@code InputEvent.KeyInputEvent} event.
4848
*
4949
* @param client The Minecraft instance performing it.
50-
* @param keyCode The key code.
50+
* @param action The action that should be performed.
5151
* @param keyEvent The key event.
5252
* @return A {@link EventResult} determining the outcome of the event,
5353
* the execution of the vanilla pressing mechanism may be cancelled by the result.
5454
*/
55-
EventResult keyPressed(Minecraft client, int keyCode, KeyEvent keyEvent);
55+
EventResult keyPressed(Minecraft client, int action, KeyEvent keyEvent);
5656
}
5757

5858
interface MouseScrolled {

fabric/src/main/java/dev/architectury/mixin/fabric/client/MixinKeyboardHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ private boolean wrapKeyReleased(Screen screen, KeyEvent keyEvent, Operation<Bool
7373
}
7474

7575
@Inject(method = "keyPress", at = @At("RETURN"), cancellable = true)
76-
public void onRawKey(long handle, int key, KeyEvent keyEvent, CallbackInfo info) {
76+
public void onRawKey(long handle, int action, KeyEvent keyEvent, CallbackInfo info) {
7777
if (handle == this.minecraft.getWindow().handle()) {
78-
var result = ClientRawInputEvent.KEY_PRESSED.invoker().keyPressed(minecraft, key, keyEvent);
78+
var result = ClientRawInputEvent.KEY_PRESSED.invoker().keyPressed(minecraft, action, keyEvent);
7979
if (result.isPresent())
8080
info.cancel();
8181
}

neoforge/src/main/java/dev/architectury/event/forge/EventHandlerImplClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ public static void eventInputEvent(InputEvent.MouseButton.Post event) {
298298

299299
@SubscribeEvent(priority = EventPriority.HIGH)
300300
public static void eventInputEvent(InputEvent.Key event) {
301-
ClientRawInputEvent.KEY_PRESSED.invoker().keyPressed(Minecraft.getInstance(), event.getKey(), event.getKeyEvent());
301+
ClientRawInputEvent.KEY_PRESSED.invoker().keyPressed(Minecraft.getInstance(), event.getAction(), event.getKeyEvent());
302302
}
303303

304304
@SubscribeEvent(priority = EventPriority.HIGH)

0 commit comments

Comments
 (0)