We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › I just want to type a word...(keyTyped)
Page Index Toggle Pages: 1
I just want to type a word...(keyTyped) (Read 635 times)
I just want to type a word...(keyTyped)
Dec 18th, 2007, 7:39pm
 
My aim is so simple.

I want to display the word I type
but using keyTyped() and then text(key,100,100);
only the letter I am typing would be displayed
so please tell me how to do so
thx!
Re: I just want to type a word...(keyTyped)
Reply #1 - Dec 18th, 2007, 8:20pm
 
i guess you will have to store the characters you type in a string and accumulate them to form the word ou type.
Re: I just want to type a word...(keyTyped)
Reply #2 - Dec 18th, 2007, 9:41pm
 
do you mean that I should stor A-Z in a string?
then how to accumulate them?
can you give me a example?
thx very much!
Re: I just want to type a word...(keyTyped)
Reply #3 - Dec 18th, 2007, 10:37pm
 
Try this

Code:

PFont myFont;
String typedWord = "";

void setup() {
size(600,50);
background(0);

myFont = createFont("Verdana", 20);
textFont(myFont);

fill(255);
}

void draw() {
background(0);
text(typedWord, 0, height-10);
}

void keyPressed() {
//println(key);
if (key != 65535) {
if (keyCode == BACKSPACE) {
if (typedWord.length() > 0) {
typedWord = typedWord.substring(0, typedWord.length()-1); //erases the last character
}
}
else {
typedWord += key; //add the key to the word
}
}
}

Page Index Toggle Pages: 1