UserInputService:GetStringForKeyCode() doesn't return KeyCodes like Space?

When I try to get string for spacebar, it returns “empty” string.
If this is intentional then I think this is bad decision, and I have to make additional checks if returned string is “empty”.

I’ve tried locating more KeyCodes which behave the same way,and I’ve found that KeyCodes like: LeftAlt, RightAlt, Space, LeftControl, RightControl and more are still affected by this issue?

I feel like this might just be intentional implementation because the keycodes names are what would probably be provided, but it creates inconsistency which isn’t very nice.

My solution for now is:

local function getKeyCodeString(keyCode)
	local keyCodeString = UserInputService:GetStringForKeyCode(keyCode)

	return keyCodeString ~= " " and keyCodeString or keyCode.Name
1 Like

We’ve filed a ticket into our internal database for this issue and will start investigating, we will update you when we have further information.

Thanks for flagging!

1 Like

Hi, @SkiuulLPcz

Thank you for inquiring about this.

I’m wondering what the expectation is here: what would you like UserInputService:GetStringForKeyCode(keyCode) to return?

I tested the function and it works as documented: it returns a string that is associated with the keycode via my keyboard (and for space I got the space character [ ]).

Your implementation seems to be working fine for the use case I think you’re trying to solve, but that seems to be different than what GetStringForKeyCode() does according to the docs.

1 Like

Hello there! Now that I read to your explanation it seems to make total sense.
I’m sorry for this useless bug report, this really is the behavior it should have and I’ve just somewhat missed the fact that this makes total sense.

I would love to propose function which could be used for “Visual” representation, but this goes beyond this bug report. I would call it something as GetVisualStringForKeyCode, but as I stated this is beyond bug report.

Sincerely sorry for wasting your time!



No worries, you raise a valid point. Feel free to file a feature request, if there are enough likes, it should be considered. Of course your solution works as well, and if you create a plugin for it, it would solve this problem for others as well.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.