From 0453ced0e9f2e0522b27604269f1cf7696f7a111 Mon Sep 17 00:00:00 2001 From: harry1064 Date: Sat, 23 Sep 2023 12:16:18 +0200 Subject: [PATCH] Fix hash of keyEvent being added to pressedKeys. When we press a letter, lets say `d` is key is char value `d` and hash calculated using keyCodea and key is added to pressed keys. But when without release `d`, if we press `SHIFT` key, hash of shift key also being added to pressedKeys. Now, when we release `d`, it is actually now `D` hence key value change and when we try to remove new hash, it doesnot exist in pressedKeys and the old hash of `d` still stays in pressedKeys which was the cause of keyPressed returning true. --- core/src/processing/core/PApplet.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index 6b1e88e4b..673624b43 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -2627,16 +2627,15 @@ protected void handleKeyEvent(KeyEvent event) { keyEvent = event; key = event.getKey(); keyCode = event.getKeyCode(); - + Long hash = ((long) keyCode << Character.SIZE); switch (event.getAction()) { case KeyEvent.PRESS -> { - Long hash = ((long) keyCode << Character.SIZE) | key; if (!pressedKeys.contains(hash)) pressedKeys.add(hash); keyPressed = true; keyPressed(keyEvent); } case KeyEvent.RELEASE -> { - pressedKeys.remove(((long) keyCode << Character.SIZE) | key); + pressedKeys.remove(hash); keyPressed = !pressedKeys.isEmpty(); keyReleased(keyEvent); }