26
26
import processing .core .PApplet ;
27
27
import processing .core .PConstants ;
28
28
import processing .core .PSurface ;
29
+ import processing .event .KeyEvent ;
29
30
import processing .event .MouseEvent ;
30
31
import processing .javafx .PSurfaceFX ;
31
32
import processing .opengl .PSurfaceJOGL ;
@@ -370,16 +371,17 @@ private boolean isMixMode() {
370
371
*/
371
372
protected void wrapProcessingVariables () {
372
373
log ("Wrap Processing built-in variables into R top context." );
373
- // TODO: Find some ways to push constants into R.
374
- wrapMouseVariables ();
374
+
375
+ this .wrapMouseVariables ();
376
+ this .wrapKeyVariables ();
377
+
375
378
this .renjinEngine .put ("width" , width );
376
379
this .renjinEngine .put ("height" , height );
377
380
this .renjinEngine .put ("displayWidth" , displayWidth );
378
381
this .renjinEngine .put ("displayHeight" , displayHeight );
379
382
this .renjinEngine .put ("focused" , focused );
380
383
this .renjinEngine .put ("pixelWidth" , pixelWidth );
381
384
this .renjinEngine .put ("pixelHeight" , pixelHeight );
382
- // this.renjinEngine.put("keyPressed", keyPressed);
383
385
}
384
386
385
387
@ Override
@@ -454,6 +456,12 @@ private void applyFunction(String name) {
454
456
}
455
457
}
456
458
459
+ @ Override
460
+ protected void handleKeyEvent (KeyEvent event ) {
461
+ super .handleKeyEvent (event );
462
+ wrapKeyVariables ();
463
+ }
464
+
457
465
@ Override
458
466
public void keyPressed () {
459
467
wrapKeyVariables ();
@@ -472,19 +480,8 @@ public void keyTyped() {
472
480
applyFunction (Constant .KEYTYPED_NAME );
473
481
}
474
482
475
- private char lastKey = Character .MIN_VALUE ;
476
-
477
483
protected void wrapKeyVariables () {
478
- if (lastKey != key ) {
479
- lastKey = key ;
480
- /*
481
- * If key is "CODED", i.e., an arrow key or other non-printable, pass that value through
482
- * as-is. If it's printable, convert it to a unicode string, so that the user can compare key
483
- * == 'x' instead of key == ord('x').
484
- */
485
- final char pyKey = key == CODED ? parseChar (Integer .valueOf (key )) : parseChar (key );
486
- this .renjinEngine .put ("key" , pyKey );
487
- }
484
+ this .renjinEngine .put ("key" , String .valueOf (key ));
488
485
this .renjinEngine .put ("keyCode" , keyCode );
489
486
this .renjinEngine .put ("keyPressedVar" , keyPressed );
490
487
}
0 commit comments