Skip to content

Commit 2b7a90b

Browse files
committed
keep track of number of keys pressed so that keyPressed works with multiple keys (fixes #4993)
1 parent 8468a48 commit 2b7a90b

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

core/src/processing/core/PApplet.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ public class PApplet implements PConstants {
658658
* @see PApplet#keyReleased()
659659
*/
660660
public boolean keyPressed;
661+
int keyPressedCount;
661662

662663
/**
663664
* The last KeyEvent object passed into a mouse function.
@@ -2934,11 +2935,13 @@ protected void handleKeyEvent(KeyEvent event) {
29342935

29352936
switch (event.getAction()) {
29362937
case KeyEvent.PRESS:
2938+
keyPressedCount++;
29372939
keyPressed = true;
29382940
keyPressed(keyEvent);
29392941
break;
29402942
case KeyEvent.RELEASE:
2941-
keyPressed = false;
2943+
keyPressedCount--;
2944+
keyPressed = (keyPressedCount == 0);
29422945
keyReleased(keyEvent);
29432946
break;
29442947
case KeyEvent.TYPE:

core/todo.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
0259 (3.3.2)
22
X add (far) more efficient file loading for loadBytes(File)
33
X add loadBytes(URL) variant that uses content length header for array size
4+
X keyPressed is false if one key is released while multiple keys are pressed
5+
X https://github.com/processing/processing/issues/4993
46

57
andres
68
X Assigning Pixels Vertically Flipped in P2D

0 commit comments

Comments
 (0)