We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am trying to modify the following code (from Amnon P5 website) to introduce four data fields from a user. The problem is that it's not possible to declare more than one string variable to be used it within keyPressed function because when I write a text in one of the field it is written at the same time the same text in all other fields. When I have defined new functions as dataField1, datafield2 it does not accept keyCode instructions, it appears a lot of small empty squares in the execution. I prefer not to use external processing GUI libraries for this if it is possible to avoid it. Any help will be very much appreciated
String myText = "Type something";
void setup() {
size(500, 500);
textAlign(CENTER, CENTER);
textSize(30);
fill(0);
}
void draw() {
background(255);
text(myText, 0, 0, width, height);
}
void keyPressed() {
if (keyCode == BACKSPACE) {
if (myText.length() > 0) {
myText = myText.substring(0, myText.length()-1);
}
} else if (keyCode == DELETE) {
myText = "";
} else if (keyCode != SHIFT && keyCode != CONTROL && keyCode != ALT) {
myText = myText + key;
}
}
Comments
An online example of input boxes:
http://studio.processingtogether.com/sp/pad/export/ro.9Zo$UbIWYZEDR/latest
You have to know which data field has the "focus". For example, when you click on the third one, you set an index variable to 2, and input goes into myText[index]; so define myText as String[4].
See also From several variables to arrays