So basically the issue is not how to run code via key press, I just want to find out what key they’re pressing.
I wrote a bit of sloppy code to get single keys:
if input.KeyCode ~= nil and input.KeyCode ~= Enum.KeyCode.Space and input.KeyCode ~= Enum.KeyCode.Backspace then
local Key = string.sub(tostring(input.KeyCode), string.len(tostring(input.KeyCode)), string.len(tostring(input.KeyCode))) end
This code takes Enum.KeyCode.S to a simple “S”
But if I were to hit Backspace for example it would change it to “e” since e is the last letter.
I want to print any key I press without using that sloppy string.sub() method
I’m completely clueless on how to accomplish this, Any help would be extremely helpful!
Thank you for the suggestion, but this actually doesn’t help me achieve what I’m looking for, It still returns “Enum.KeyCode.S” and I’m just trying to get the string “S”
Enums are UserData, not string. Here’s an example script you could use:
-- key = Enum.KeyCode.A
tostring(key):split(".")[3]
-- string:split(seperator) returns an ordered array of the elements
-- in our case, we'd get Enum, Keycode, A
EDIT: While this would work, @sircfenner’s solution is much more efficient and I’d strongly recommenced using it over this method!
All three of you gave me solutions, I find this one to be a lot more efficient, Thank you.
I wish I could mark more replies as solutions, Sadly I cannot so to @ElliottLMz and @mistrustfully thank you for your suggestion, I did not know string.split existed and I was going to ask around if something like this was possible, Thank you much!