Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char key_pressed;
- PFont f;
- // Variable to store text currently being typed
- String typing = "";
- // Variable to store saved text when return is hit
- String saved = "";
- void setup() {
- size(500, 500);
- f = createFont("Arial",16,true);
- }
- void draw() {
- background(255);
- int indent = 25;
- // Set the font and fill for text
- textFont(f);
- fill(0);
- // Display everything
- text("Click in this applet and type. \nHit return to save what you typed. ", indent, 40);
- text(typing,indent,90);
- text(saved,indent,130);
- }
- void keyPressed() {
- if ((key >= 65 && key < 90) | (key >= 97 && key < 122)){
- key_pressed = (char)(key + 1);
- }
- else if (key == 91 | key == 122) {
- key_pressed = (char)65;
- }
- // If the return key is pressed, save the String and clear it
- if (key == '\n' ) {
- saved = typing;
- // String is cleared by setting it equal to ""
- typing = "";
- } else {
- //Otherwise, concatenate the String
- // Each character typed by the user is added to the end of the String variable.
- typing = typing + key_pressed;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement