- Home /
Checking whether string is a valid Input.Key
Hi, lets say I have a string X which should be used as Input.KeyUp(x). however, it will change during runtime and it may contain a string that its not a "valid" key string so it would throw an exception. can I somehow check whether the string X is a valid key? (so I could ignore if its not)
Why would you ever do that? Using a variable string to identify static concepts - key inputs - seems like a bad idea. Could you explain what you're doing in a bit more detail?
You could make a list of all the keys you use, and check if your x is in that list, but you probably should rethink what you're doing.
well I have my own input manager which lets me change my key bindings from the game itself so I don't have to use that ugly unity starter (since the unity's input manager doesn't allow change of key bindings at runtime). As it is a multi platform game sometimes some keys are misread on other OSs so I wanted to avoid the errors and ignore them. Anyway I've already figured a way to overcome this but thanks for the effort
Answer by recon472 · Sep 27, 2014 at 05:06 PM
ok I already figured it out: (the catch part will happen only if it fails)
try
{
Input.GetKey(key);
}
catch
{
Debug.Log("aaa");
}