@@ -54,6 +54,31 @@ public double getPI() {
5454 return PI ;
5555 }
5656
57+ @ Override
58+ public void mouseClicked () {
59+ wrapMouseVariables ();
60+ }
61+
62+ @ Override
63+ public void mouseMoved () {
64+ wrapMouseVariables ();
65+ }
66+
67+ @ Override
68+ public void mousePressed () {
69+ wrapMouseVariables ();
70+ }
71+
72+ @ Override
73+ public void mouseReleased () {
74+ wrapMouseVariables ();
75+ }
76+
77+ @ Override
78+ public void mouseDragged () {
79+ wrapMouseVariables ();
80+ }
81+
5782 /**
5883 *
5984 * @see processing.core.PApplet#focusGained()
@@ -74,16 +99,42 @@ public void focusLost() {
7499 this .renjinEngine .put ("focused" , super .focused );
75100 }
76101
77- @ Override
78- public void mouseMoved () {
79- wrapMouseVariables ();
80- }
81-
82102 protected void wrapMouseVariables () {
83103 this .renjinEngine .put ("mouseX" , mouseX );
84104 this .renjinEngine .put ("mouseY" , mouseY );
85105 this .renjinEngine .put ("pmouseX" , pmouseX );
86106 this .renjinEngine .put ("pmouseY" , pmouseY );
87107 // this.renjinEngine.put("mouseButton", mouseButton);
88108 }
109+
110+ @ Override
111+ public void keyPressed () {
112+ wrapKeyVariables ();
113+ }
114+
115+ @ Override
116+ public void keyReleased () {
117+ wrapKeyVariables ();
118+ }
119+
120+ @ Override
121+ public void keyTyped () {
122+ wrapKeyVariables ();
123+ }
124+
125+ private char lastKey = Character .MIN_VALUE ;
126+
127+ protected void wrapKeyVariables () {
128+ if (lastKey != key ) {
129+ lastKey = key ;
130+ /*
131+ * If key is "CODED", i.e., an arrow key or other non-printable, pass that
132+ * value through as-is. If it's printable, convert it to a unicode string,
133+ * so that the user can compare key == 'x' instead of key == ord('x').
134+ */
135+ final char pyKey = key == CODED ? parseChar (Integer .valueOf (key )) : parseChar (key );
136+ this .renjinEngine .put ("key" , pyKey );
137+ }
138+ this .renjinEngine .put ("keyCode" , keyCode );
139+ }
89140}
0 commit comments