How to convert "Enum.Keycode" to a string value?

So I am currently making a keybind engine but what I just need to know:

“How to convert something like “Enum.KeyCode” to a letter(string)?”
This is what the code is:

game:GetService("UserInputService").InputBegan:Connect(function(Input, gameProccessedEvent)
	print(Input.KeyCode)
end)

and this is what it prints out when I press the ‘J’ key

-Enum.KeyCode.J

So my question for today is how do I convert this line so that it just prints out the letter J?

Thank you in advance! :smiley:

1 Like

If we’re talking KeyCodes here, I think this is what you want:

print(UserInputService:GetStringForKeyCode(Input.KeyCode))

This function should require a KeyCode value, & would return back the string provided by what the User Pressed (Or in this case, “J”)

8 Likes

@JackscarIitt’s solution will work fine for KeyCode Enums. There is also a lesser known way to do this however. Each enum is represented by an EnumItem. This object has properties Name, Value, and EnumType. To convert Enum.KeyCode.E to a string value you could also just use Enum.KeyCode.E.Name.

3 Likes

try
:GetStringForKeyCode(Input.KeyCode)

This won’t work for all cases; for example, if you press space, Enum.KeyCode.Space.Name will give you the string "Space", which is probably not what you want. You’re probably looking for the string ' '.

2 Likes