You get random values because if the key is not found in getKey, then there is no return statement.
You attach the \n to the key in serialEvent(), then the key for getKey is "key1\n" and it is not found.
void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
if (inChar == '\n') {
stringComplete = true;
} else {
inputString += inChar;
}
}
}
If you have CR/LF set in Serial Monitor, then the \r character is send too and the parsed key is "key1\r\n".
thereThere are obsolete things in your code, like the this->* or Uno::. Make the map std::map<String, int> keys;, because now you mix pointers and ints.