UserInputService GetStringForKeyCode documentation

Under the “System Images for KeyCodes” header, inside the table containing KeyCode, Image and Asset ID there is a non-existent KeyCode (Enum.KeyCode.Apostrophe, supposed to be Enum.KeyCode.Quote). I am also confused why UserInputService:GetImageForKeyCode() returns an empty string for every KeyCode in the table after Enum.KeyCode.Thumbstick2, however the Asset IDs provided are correct. I know there is an easy work-around below, but it just seems weird.

local UserInputService = game:GetService("UserInputService")

local keyCodeToImage = {
	[Enum.KeyCode.Backspace] = "rbxasset://textures/ui/Controls/backspace.png",
	[Enum.KeyCode.Return] = "rbxasset://textures/ui/Controls/return.png",
	[Enum.KeyCode.LeftShift] = "rbxasset://textures/ui/Controls/shift.png",
	[Enum.KeyCode.RightShift] = "rbxasset://textures/ui/Controls/shift.png",
	[Enum.KeyCode.Tab] = "rbxasset://textures/ui/Controls/tab.png",
	[Enum.KeyCode.Quote] = "rbxasset://textures/ui/Controls/apostrophe.png",
	[Enum.KeyCode.Comma] = "rbxasset://textures/ui/Controls/comma.png",
	[Enum.KeyCode.Backquote] = "rbxasset://textures/ui/Controls/graveaccent.png",
	[Enum.KeyCode.Period] = "rbxasset://textures/ui/Controls/period.png",
	[Enum.KeyCode.Space] = "rbxasset://textures/ui/Controls/spacebar.png",
}

local function getImageForKeyCode(keyCode: Enum.KeyCode): string
	return keyCodeToImage[keyCode] or UserInputService:GetImageForKeyCode(keyCode)
end

print(getImageForKeyCode(Enum.KeyCode.Backspace)) -- returns "rbxasset://textures/ui/Controls/backspace.png"
print(getImageForKeyCode(Enum.KeyCode.ButtonA)) -- returns "rbxasset://textures/ui/Controls/DefaultController/ButtonA@2x.png"
print(getImageForKeyCode(Enum.KeyCode.E)) -- returns "" (empty string)

Page URL: https://create.roblox.com/docs/reference/engine/classes/UserInputService#GetStringForKeyCode

1 Like

Made a pull request regarding the inconsistency for the Apostrophe KeyCode changing it to instead reference Enum.KeyCode.Quote and renamed the associated image file to quote.png instead of apostrophe.png here.

As for the bug regarding UserInputService:GetImageForKeyCode() returning empty strings, I would recommend filing a seperate bug report under #bug-reports:engine-bugs.

1 Like

GetImageForKeyCode only supports gamepad:

GetImageForKeyCode

ContentId

This method takes the requested Enum.KeyCode and returns the associated image for the currently connected gamepad device (limited to Xbox, PlayStation and Windows).

from: UserInputService:GetImageForKeyCode

cc: @Mmm_Wafflez

1 Like

Interesting, I don’t know why they wouldn’t provide support for all KeyCode enums.

1 Like

They probably didn’t want to make 104 icons of keys :upside_down_face:

Also this should totally error or at least report a warning, I swear I’ve seen this exact thing be reported before

From what I understand, they exist, but just aren’t accessible via that method. That’s why they can still be accessed via the work-around in the original post.

I tried looking through the folder Roblox gets the assets from, there don’t seem to be any key icons other than the modifier keys like Shift and punctuation listed on the Documentation.

If it’s somewhere in the files, it’s not obvious

I think they were specifically talking about the entries in the list “System Images for KeyCodes” under Get String for KeyCode. All of these entries exist in the image you just posted, but when attempting to use UserInputService:GetImageForKeyCode() on any of the Enums after Enum.KeyCode.Thumbstick2 the returned ContentId is empty. Sorry for the confusion, I was not discussing KeyCodes for all keys in general.

1 Like