@@ -54,6 +54,31 @@ public double getPI() {
54
54
return PI ;
55
55
}
56
56
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
+
57
82
/**
58
83
*
59
84
* @see processing.core.PApplet#focusGained()
@@ -74,16 +99,42 @@ public void focusLost() {
74
99
this .renjinEngine .put ("focused" , super .focused );
75
100
}
76
101
77
- @ Override
78
- public void mouseMoved () {
79
- wrapMouseVariables ();
80
- }
81
-
82
102
protected void wrapMouseVariables () {
83
103
this .renjinEngine .put ("mouseX" , mouseX );
84
104
this .renjinEngine .put ("mouseY" , mouseY );
85
105
this .renjinEngine .put ("pmouseX" , pmouseX );
86
106
this .renjinEngine .put ("pmouseY" , pmouseY );
87
107
// this.renjinEngine.put("mouseButton", mouseButton);
88
108
}
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
+ }
89
140
}
0 commit comments