Discard auto-repeated keys in P2D/P3D

This commit is contained in:
Jakub Valtar
2015-08-17 19:45:00 -04:00
parent 7137cd9701
commit 475e83fbdc
5 changed files with 46 additions and 5 deletions
+9
View File
@@ -371,6 +371,11 @@ public class PApplet implements PConstants {
*/
public int pixelHeight;
/**
* Keeps track of ENABLE_KEY_AUTO_REPEAT hint
*/
protected boolean isKeyAutoRepeatEnabled = false;
/**
* ( begin auto-generated from mouseX.xml )
*
@@ -2911,6 +2916,10 @@ public class PApplet implements PConstants {
protected void handleKeyEvent(KeyEvent event) {
// Get rid of auto-repeating keys if desired and supported
if (!isKeyAutoRepeatEnabled && event.isAutoRepeat()) return;
keyEvent = event;
key = event.getKey();
keyCode = event.getKeyCode();
+6 -3
View File
@@ -514,8 +514,11 @@ public interface PConstants {
static final int ENABLE_STROKE_PURE = 9;
static final int DISABLE_STROKE_PURE = -9;
static final int ENABLE_BUFFER_READING = 10;
static final int DISABLE_BUFFER_READING = -10;
static final int ENABLE_BUFFER_READING = 10;
static final int DISABLE_BUFFER_READING = -10;
static final int HINT_COUNT = 11;
static final int DISABLE_KEY_AUTO_REPEAT = 11;
static final int ENABLE_KEY_AUTO_REPEAT = -11;
static final int HINT_COUNT = 12;
}
+10
View File
@@ -1119,6 +1119,11 @@ public class PGraphics extends PImage implements PConstants {
* hint(DISABLE_DEPTH_READING) if you don't plan to read depth from
* this PGraphics anymore.
* <br/> <br/>
* hint(ENABLE_KEY_AUTO_REPEAT) - Auto-repeating key events are discarded
* by default (works only in P2D/P3D); use this hint to get all the key events
* (including auto-repeated). Call hint(DISABLE_KEY_AUTO_REPEAT) to get events
* only when the key goes physically up or down.
* <br/> <br/>
* As of release 0149, unhint() has been removed in favor of adding
* additional ENABLE/DISABLE constants to reset the default behavior. This
* prevents the double negatives, and also reinforces which hints can be
@@ -1139,6 +1144,11 @@ public class PGraphics extends PImage implements PConstants {
showWarning("hint(ENABLE_NATIVE_FONTS) no longer supported. " +
"Use createFont() instead.");
}
if (which == ENABLE_KEY_AUTO_REPEAT) {
parent.isKeyAutoRepeatEnabled = true;
} else if (which == DISABLE_KEY_AUTO_REPEAT) {
parent.isKeyAutoRepeatEnabled = false;
}
if (which > 0) {
hints[which] = true;
} else {
+17
View File
@@ -31,6 +31,8 @@ public class KeyEvent extends Event {
char key;
int keyCode;
boolean isAutoRepeat;
public KeyEvent(Object nativeObject,
long millis, int action, int modifiers,
@@ -41,6 +43,16 @@ public class KeyEvent extends Event {
this.keyCode = keyCode;
}
public KeyEvent(Object nativeObject,
long millis, int action, int modifiers,
char key, int keyCode, boolean isAutoRepeat) {
super(nativeObject, millis, action, modifiers);
this.flavor = KEY;
this.key = key;
this.keyCode = keyCode;
this.isAutoRepeat = isAutoRepeat;
}
public char getKey() {
return key;
@@ -50,4 +62,9 @@ public class KeyEvent extends Event {
public int getKeyCode() {
return keyCode;
}
public boolean isAutoRepeat() {
return isAutoRepeat;
}
}
+4 -2
View File
@@ -924,7 +924,8 @@ public class PSurfaceJOGL implements PSurface {
KeyEvent ke = new KeyEvent(nativeEvent, nativeEvent.getWhen(),
peAction, peModifiers,
keyChar,
keyCode);
keyCode,
nativeEvent.isAutoRepeat());
sketch.postEvent(ke);
@@ -935,7 +936,8 @@ public class PSurfaceJOGL implements PSurface {
KeyEvent tke = new KeyEvent(nativeEvent, nativeEvent.getWhen(),
KeyEvent.TYPE, peModifiers,
keyChar,
0);
keyCode,
nativeEvent.isAutoRepeat());
sketch.postEvent(tke);
}