PFont f; int leftmargin = 10; int rightmargin = 20; String buff = ""; boolean didntTypeYet = true; void setup() { size(400, 400, P3D); background(2, 233, 23); f = loadFont("CCDutchCourage-BlackAndTan-48.vlw"); fill(12, 233, 66, 3); textFont(f, 25); } void draw() { background(176); if((millis() % 500) < 250){ // Only fill cursor half the time noFill(); } else{ fill(0); } float rPos; // Store the cursor rectangle's position rPos = textWidth(buff)+leftmargin; rect(rPos+1, 29, 10, 21); if(didntTypeYet){ fill(0); //text("Use the keyboard.", 22, 40); } fill(15, 22, 100); pushMatrix(); translate(rPos,10+25); char k; for(int i=0;i0){ buff = buff.substring(1); } break; case 13: // Avoid special keys case 10: case 65535: case 127: case 27: break; default: if(textWidth(buff+k)+leftmargin < width-rightmargin){ didntTypeYet = false; buff=k+buff; } break; } }