Showing words at maxium of 12

I’ve created this code where every key is a pre formatted word and once it has been pressed it shows the word on screen and pressing another key changes the previous word. Now I’m wondering, can I show more than one word at once (12 for example) and when twelve words are on screen and the thirteen word has been pressed, the first one gets deleted. I know it’s possible, but I don’t how.

PFont font;

String myText = "Testing part"; // Starting Text, is only vissable once pressed

String aKPInput = "Medium"; // Input Key : A
String bKPInput = "Is"; // Input Key : B
String cKPInput = "The"; // Input Key : C
String dKPInput = "Message"; // Input Key : D
String eKPInput = "Conversation"; // Input Key : E
String fKPInput = "On"; // Input Key : F
String gKPInput = "We"; // Input Key : G
String hKPInput = "Contact"; // Input Key : H
String iKPInput = "Greenlight"; // Input Key : I
String jKPInput = "Processing"; // Input Key : J
String kKPInput = "Fake News"; // Input Key : K
String lKPInput = "Networking"; // Input Key : L
String mKPInput = "Enlightment"; // Input Key : M
String nKPInput = "Are"; // Input Key : N
String oKPInput = "Concept"; // Input Key : O
String pKPInput = "MAP"; // Input Key : P
String qKPInput = "Walking"; // Input Key : Q
String rKPInput = "Sunshine"; // Input Key : R
String sKPInput = "Greyscale"; // Input Key : S
String tKPInput = "Who"; // Input Key : T
String uKPInput = "Questionmark"; // Input Key : U
String vKPInput = "Probably"; // Input Key : V
String wKPInput = "And"; // Input Key : W
String xKPInput = "I"; // Input Key : X
String yKPInput = "Like"; // Input Key : Y
String zKPInput = "Big Butts"; // Input Key : Z

//int wordsDisplay = 5;
// float wordsDisplay = 5;

void setup() {
  size(1280, 720);
  font = createFont("Sans Serif", 80);
  textFont(font, 120);
  textAlign(CENTER, CENTER);
}

void draw() {
  background(0);
 // for (int i = 0; i < wordsDisplay; i++) {
     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) {
   myText = myText + key;
   } 
   */

  switch(key) {
  case 'a': // KEYBOARD A 
    myText = aKPInput;
    break;
  case 'b': // KEYBOARD B
    myText = bKPInput;
    break;
  case 'c': // KEYBOARD C 
    myText = cKPInput;
    break;
  case 'd': // KEYBOARD D 
    myText = dKPInput;
    break;
  case 'e': // KEYBOARD E 
    myText = eKPInput;
    break;
  case 'f': // KEYBOARD F
    myText = fKPInput;
    break;
  case 'g': // KEYBOARD G
    myText = gKPInput;
    break; 
  case 'h': // KEYBOARD H 
    myText = hKPInput;
    break;
  case 'i': // KEYBOARD I 
    myText = iKPInput;
    break; 
  case 'j': // KEYBOARD J 
    myText = jKPInput;
    break; 
  case 'k': // KEYBOARD K 
    myText = kKPInput;
    break;
  case 'l': // KEYBOARD L 
    myText = lKPInput;
    break;
  case 'm': // KEYBOARD M 
    myText = mKPInput;
    break;
  case 'n': // KEYBOARD N 
    myText = nKPInput;
    break;
  case 'o': // KEYBOARD O
    myText = oKPInput;
    break;
  case 'p': // KEYBOARD P
    myText = pKPInput;
    break;
  case 'q': // KEYBOARD Q 
    myText = qKPInput;
    break;
  case 'r': // KEYBOARD R 
    myText = rKPInput;
    break;
  case 's': // KEYBOARD S
    myText = sKPInput;
    break;
  case 't': // KEYBOARD T 
    myText = tKPInput;
    break;
  case 'u': // KEYBOARD U 
    myText = uKPInput;
    break;
  case 'v': // KEYBOARD V
    myText = vKPInput;
    break;
  case 'w': // KEYBOARD W 
    myText = wKPInput;
    break;
  case 'x': // KEYBOARD X 
    myText = xKPInput;
    break;
  case 'y': // KEYBOARD Y 
    myText = yKPInput;
    break;
  case 'z': // KEYBOARD Z 
    myText = zKPInput;
    break;
  }
}

no answer to your question, but think about using a array?
https://processing.org/reference/Array.html

PFont font;

String[] kPInput = {
  "test", 
  "Medium", // Input Key : A
  "Is", // Input Key : B
  "The", // Input Key : C
  "Message", // Input Key : D
  "Conversation", // Input Key : E
  "On", // Input Key : F
  "We", // Input Key : G
  "Contact", // Input Key : H
  "Greenlight", // Input Key : I
  "Processing", // Input Key : J
  "Fake News", // Input Key : K
  "Networking", // Input Key : L
  "Enlightment", // Input Key : M
  "Are", // Input Key : N
  "Concept", // Input Key : O
  "MAP", // Input Key : P
  "Walking", // Input Key : Q
  "Sunshine", // Input Key : R
  "Greyscale", // Input Key : S
  "Who", // Input Key : T
  "Questionmark", // Input Key : U
  "Probably", // Input Key : V
  "And", // Input Key : W
  "I", // Input Key : X
  "Like", // Input Key : Y
  "Big" // Input Key : Z
};

void setup() {
  size(200, 200);
  //println( PFont.list() );
  font = createFont("Sans Serif", 20);
  textFont(font, 20);
  textAlign(CENTER, CENTER);
}

void draw() {
  background(0);
  text(kPInput[k], 0, 0, width, height);
}

int k = 0;

void keyPressed() {
  k = keyCode - 64;
  println("key "+key+" keyCode "+keyCode+ " k "+k);
}


next try to use a
https://processing.org/reference/IntList.html
to store 12 last keys

IntList ks = new IntList();
//..
ks.append(k);
if ( ks.size() > 12 ) ks.remove(0);
2 Likes