issue with Input.inputString blanks

Hello everyone! I’m new to unity, and building a game for a class. I’m having a small issue with Input.inputString. (I saw that there were issues at some point with this on Mac, but I am on Windows 7 and did not see any threads saying this method was bugged on this OS).

What I’m trying to do is record every time the player pressed “w”, “e”, “a”, and “d”, as well as the time they pressed it, or released it. Right now I have a GameObject called KeyRecorder that runs the following code every frame, which (hopefully) adds a new entry into my recording every time a relevant key is pressed or released:

HashSet<char> diffPresses = new HashSet<char>(Input.inputString.ToCharArray());
diffPresses.IntersectWith(keysToRecord);
if (!diffPresses.SetEquals(curKeypresses)) {
     StringBuilder sb = new StringBuilder();
     foreach (char c in diffPresses) {
          sb.Append(c);
     }
     curKeypresses = diffPresses;
     curRecording.Add(new KeyTimePair(sb.ToString(), Time.time - startTime));
}

keysToRecord is a hashset containing the characters ‘w’, ‘a’, ‘d’, ‘e’.
startTime is the time this GameObject was created.
curKeypresses is where I store the current keys being pressed to check against every frame for differences.
KeyTimePair is just a pair of string and float denoting the keys and the time relative to the gameobject spawning.

My issue is that whenever I press a key, I’ll get two entries, one with the key (like “d”, 5.34187), and a second really soon after with an empty string (like “”, 5.356074) which seems to be the frame right after I pressed “d”. This is causing issues with when I try to play back the recordings. I tried to prune out blanks, but that also causes issues since I need to know if no keys are being pressed at a given time. Does anyone know why this is happening, and how I could fix it?

I’m running on Unity 5.6.0f3 Personal 64-bit, if that’s important

Thanks!

If you are only looking for the four keys, why not check them directly?

I might lend up doing that…

Originally I wanted to abstract away the need to check for individual keys since for the class I’m getting graded on “best practices”, so I didn’t want multiple blocks of similar code. I also wasn’t sure if I was going to incorporate additional keys in the future (it would’ve been the greatest feeling if I could just add an entry to my initial hashset and be done!).

For any future lost souls who may stumble upon this thread, the issue is that inputString only gets keys that were pressed that frame instead of all keys that are currently pressed.