Processing.js: KeyPress
in
Processing with Other Languages
•
1 year ago
Hi,
i have some code here:
String typedText = "",
formText[],
newFormData[],
oldFormData[],
DataToFile[] ;
PrintWriter pwOut = null ;
String sOutFileName = "http://alumni.vgtusa.lt/sketches/data/Alumni-Duomenys.csv" ;
PFont font ;
int i = 0, k = 0, ilgis ;
boolean bSucessfulInput = false ;
void setup ( ) {
size ( 800, 60 ) ;
font = createFont ( "Nimbus Sans L", 18 ) ;
formText = loadStrings ( "http://alumni.vgtusa.lt/sketches/data/d.txt" ) ;
oldFormData = loadStrings ( sOutFileName ) ;
newFormData = new String [ 1 ] ;
DataToFile = new String [ oldFormData.length + newFormData.length ] ;
ilgis = formText.length ;
i = 0 ;
newFormData [ 0 ] = "";
}
void draw() {
background(255);
fill(255,0,0);
textFont(font, 50);
if ( bSucessfulInput )
{
text("Jūsų duomenys sėkmingai išsaugoti", 0, 45);
}
else
{
text ( formText[i], 0, 45 ) ;
text ( typedText + ( frameCount/10 % 2 == 0 ? "_" : "" ), textWidth ( formText[i]) + 10, 45 ) ;
}
}
void keyReleased() {
if (key != CODED) {
switch(key) {
case BACKSPACE:
typedText = typedText.substring(0,max(0,typedText.length()-1));
break;
case TAB:
break;
case ENTER:
case RETURN:
typedText += ";" ;
newFormData [ 0 ] += typedText ;
typedText = "";
if ( i < ilgis )
{
i ++ ;
if ( i == ilgis )
{
for ( k = 0 ; k < oldFormData.length ; k ++ )
{
DataToFile [ k ] = oldFormData [ k ] ;
}
DataToFile [ DataToFile.length - 1 ] = newFormData [ 0 ] ;
saveStrings ( sOutFileName, DataToFile ) ;
bSucessfulInput = true ;
i = 0 ;
}
}
break;
case ESC:
case DELETE:
break;
default:
typedText += key;
bSucessfulInput = false ;
}
}
}
And the problem is that is shows on screen keycode. It does not capture the code.. Even if i try example with exact keycodes (as in here:
http://processingjs.org/reference/globalKeyEvents/) ir does not work. Although it work in my computer with processing compiler.
formText[],
newFormData[],
oldFormData[],
DataToFile[] ;
PrintWriter pwOut = null ;
String sOutFileName = "http://alumni.vgtusa.lt/sketches/data/Alumni-Duomenys.csv" ;
PFont font ;
int i = 0, k = 0, ilgis ;
boolean bSucessfulInput = false ;
void setup ( ) {
size ( 800, 60 ) ;
font = createFont ( "Nimbus Sans L", 18 ) ;
formText = loadStrings ( "http://alumni.vgtusa.lt/sketches/data/d.txt" ) ;
oldFormData = loadStrings ( sOutFileName ) ;
newFormData = new String [ 1 ] ;
DataToFile = new String [ oldFormData.length + newFormData.length ] ;
ilgis = formText.length ;
i = 0 ;
newFormData [ 0 ] = "";
}
void draw() {
background(255);
fill(255,0,0);
textFont(font, 50);
if ( bSucessfulInput )
{
text("Jūsų duomenys sėkmingai išsaugoti", 0, 45);
}
else
{
text ( formText[i], 0, 45 ) ;
text ( typedText + ( frameCount/10 % 2 == 0 ? "_" : "" ), textWidth ( formText[i]) + 10, 45 ) ;
}
}
void keyReleased() {
if (key != CODED) {
switch(key) {
case BACKSPACE:
typedText = typedText.substring(0,max(0,typedText.length()-1));
break;
case TAB:
break;
case ENTER:
case RETURN:
typedText += ";" ;
newFormData [ 0 ] += typedText ;
typedText = "";
if ( i < ilgis )
{
i ++ ;
if ( i == ilgis )
{
for ( k = 0 ; k < oldFormData.length ; k ++ )
{
DataToFile [ k ] = oldFormData [ k ] ;
}
DataToFile [ DataToFile.length - 1 ] = newFormData [ 0 ] ;
saveStrings ( sOutFileName, DataToFile ) ;
bSucessfulInput = true ;
i = 0 ;
}
}
break;
case ESC:
case DELETE:
break;
default:
typedText += key;
bSucessfulInput = false ;
}
}
}
What should i do and what is wrong?
My code in the internet:
http://alumni.vgtusa.lt/ and when you click (make active) the sketch you can try to write... On backspace it should delete a letter (it works on my computer, but not online), when you press enter - it should change the text before " : ", and when you press any letter it should show it on screen (again, it works on my screen).
Have you any thoughts?
Thank you for your time..
Have you any thoughts?
Thank you for your time..
1