Add something like SpecialKeyPressed to have a UserInputService that would get input in a keyboard layout friendly way

As a Roblox developer, it is currently too hard to assign the right keybinds that matches everyone’s keyboard layout.

Even for Roblox. Enum.KeyCode.Slash showing as - because it’s only the key’s position on the keyboard.
image
 

I need something that is keyboard layout friendly. Something like SpecialKeyPressed, which seems to return the string output from the key that you pressed. Which sounds just perfect!

Imagine a TextBox where you can type in. If I press K, it will send K. If I press SHIFT + 1 on US Layout, it will send !

and I need something that is like UserInputService.InputBegan, but when I press SHIFT + 1, it would send !

If I want to listen for Enum.KeyCode.Slash, what I have in mind is /. But if I use UserInputService.GetStringForKeycode it actually turns into a - for me.

I’d have to add more line in my code. That would have to listen for Enum.KeyCode.KeypadDivide which would be / on my NumPad. But “GetStringForKeycode” doesn’t even display the string for it!

And what about the other keys? Maybe there’s another way to get a / that I do not know the Enum.KeyCode of, but it exists in a keyboard language layout…

So it’s just too hard and a pain of a workaround, to implement a keyboard layout friendly input.

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(input)
	local inputInLang = UserInputService:GetStringForKeyCode(input.KeyCode)
	
	print(input.KeyCode, inputInLang)
end)

I can do this, to turn Z and Y into the Player’s keyboard language representation. But that’s about it.
 

If this issue is addressed, it would improve my development experience because no longer will I have to do workarounds just do get a key bound the right way. I would be able to say that I want to bind a key to Y and it will be Y for everyone else.

This is actually even possible right now, but only for /.

Roblox has a GuiService which has a hidden method called SpecialKeyPressed which is part of the Legacy Chat.

It has the capability that I was looking for. I can press SHIFT + 7, which creates a / and it would open the chat bar, aka. the input matched the wanted Hotkey.

I can press / on my numpad and it would match the wanted Hotkey.

I can finally listen for the “string output” that a key would give. And I think that would be a cool and useful feature to have on Roblox. It would help with a lot of stuff regarding hotkeys.
That’s what SpecialKeyPressed does, but only for defined SpecialKey Enum’s. I’d want to see it altered.

And if someone does plan to add this. Then please with a way so that the developer can control whether keys where you have to hold down SHIFT, should get counted or not.

I always saw it as annoying. SHIFT is usually the key a lot of people bind to make the character run. And if I wanted to equip Slot 7 on my keyboard, it would have counted as a / input and opened the chat.

 

Here’s a forum thread https://devforum.roblox.com/t/id-like-to-tell-you-about-textchatservice-and-specialkeypressed/2525959

6 Likes