Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions core/src/processing/core/PApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ public class PApplet implements PConstants {
* @see PApplet#keyReleased()
*/
public boolean keyPressed;
int keyPressedCount;
List<Long> pressedKeys = new ArrayList<>(6);

/**
* The last KeyEvent object passed into a mouse function.
Expand Down Expand Up @@ -2935,13 +2935,14 @@ protected void handleKeyEvent(KeyEvent event) {

switch (event.getAction()) {
case KeyEvent.PRESS:
keyPressedCount++;
Long hash = ((long) keyCode << Character.SIZE) | key;
if (!pressedKeys.contains(hash)) pressedKeys.add(hash);
keyPressed = true;
keyPressed(keyEvent);
break;
case KeyEvent.RELEASE:
keyPressedCount--;
keyPressed = (keyPressedCount > 0);
pressedKeys.remove(((long) keyCode << Character.SIZE) | key);
keyPressed = !pressedKeys.isEmpty();
keyReleased(keyEvent);
break;
case KeyEvent.TYPE:
Expand Down Expand Up @@ -3123,7 +3124,10 @@ public void keyTyped(KeyEvent event) {
public void focusGained() { }


public void focusLost() { }
public void focusLost() {
// TODO: if user overrides this without calling super it's not gonna work
pressedKeys.clear();
}



Expand Down