User Interface, Using A buffer with a module

Every iteration of loop(), the code checks if there are characters available and if so it reads them and adds it to a buffer 'receivedChars'. When a '\n' (linefeed) is received, it replaces it with the string terminator '\0' and places that in the buffer. 'ndx' (index) indicates where the character must be placed in the buffer; it starts with 0 and increments every time a character is received.

+-----+-----+-----+-----+-----+-----+-----
| 'a' | 'b' | 'c' | '\0'|     |     |
+-----+-----+-----+-----+-----+-----+-----

When the '\n' is received, a flag is set to indicate that the message is complete and sets 'ndx' to 0 for the next time that one needs to read data.

The flag is used in showNewData() and it will show the new text if the flag was set. It will clear the flag to indicate that there is no longer new data (it was processed).

I think that you need to add some debug statements to your recvWithEndMarker.

  while (keyboard.available() > 0 && newData == false)
  {
    Serial.println("characters available");
    rc = keyboard.read();
    Serial.print(rc, HEX);

    if (rc != endMarker)
    {
      ...
      ...
    }
    else
    {
      Serial.println("  endMarker received");
      ...
      ...
    }
}

This way you can follow what was received. On your keyboard, type some characters like 'a', 'b' etc and press .

Tell us what you typed and what the result in the serial monitor is.

For a 'a', you should see 61, for a 'b' 62 and so on. For a '0' you should see '30', for '1' you should see '31' etc. See asciitable.com

If you see different data in the serial monitor, you get raw keyboard output instead of ascii characters. Please provide links to the libraries that you use and the hardware that you use to connect the PS keyboard to the Arduino. Also, which Arduino do you use?