Some compilers (ehm, microsoft) returns a temporary variable for event.key.getKeyName() that is only valid during the statement and not scope. Fix this by storing std::string instead. So the object's lifetime is the entire if statement.