Enum.KeyCode on International Keyboards

Problem:
[When I originally typed this question, I wasn’t sure on some aspects, so some things are “discovered” throughout the problem description. This makes it look poorly worded. Please stick though or skip to the question at the end if you can help, this is a bit more of a theoretical question.]

We all know that different countries have different keyboard layouts,
But how would Enum.KeyCode and UserInputService work with this?

I ask because of the hash key (#) [save me the naming debate please].
On a British Keyboard, this is it’s own key adjacent to the enter key.
However on an American Keyboard, This is located on the 3 key and typed when shift is also pressed.

So if I wanted to use the # key to activate something (and I do), I think just using KeyCode 92 wouldn’t be good enough.

Playing about on studio with this simple script:

function onKeyPress(inputObject, gameProcessedEvent)
    print(inputObject.KeyCode.Value)
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)

If I try and press one of the shift accessible letters from my keyboard, it fires two separate events for both shift and the key.

I take it this is as these are designed for key presses rather than character inputs…

Question:
So I ask, is there an [quick] alternate method, to just capture character input key press?

You can directly compare the key codes instead of their values, such as below (I’m on mobile, so excuse the lack of variables)

UserInputService.InputBegan:Connect(function(Key, GameProcessedEvent)
    if GameProcessedEvent then return end

    if Key.KeyCode == Enum.KeyCode.Hash then
        - - code
    end
end)

edit: This may not be what you are looking for. Your question seems quite unclear to me.

Excuse me, sorry, was late night, language must have gone to sleep.

I should have asked if there is a simple way for a function to be executed once an input of a specific character has been entered.

I was just using the number rather than the name of the enum so I’m not sure that will help.

Using the name of an enum should work, providing you are interested in just 1 character and not a series of input. I posted a code snippet above if that works for you.

From the testing I’ve done (pressing the tilde (~) key on a UK QWERTY keyboard), UserInputService doesn’t work with international keyboard layouts, neither does it seem to work with keys that require pressing Shift or another key e.g. Right Alt or Alt Gr. Instead, it recognises the Shift key (or equivalent) and the main key that’s in that spot according to the US layout.

image

As you can see, it recognises the Left Shift character, and then the backslash (\) symbol, even though my actual keyboard would type an octothorp (#) in that space. The backslash symbol is also used in that place in the US keyboard layout.

I also tried using ContextActionService, thinking that would support it. Nope - it doesn’t.
I finally tried checking my keyboard on different games to check if this was Roblox-related. The results were interesting.

I tried it out on three games - Rocket League, Golf With Your Friends and one more game.
Since using Shift and another key usually doesn’t work in games, I just went for the octothorp symbol.

Both Rocket League and Golf With Your Friends mistake it for the apostrophe symbol.
image

However, the other game correctly identifies it as an octothorp.

Although most of the games I tested got it wrong, these games allow you to change your keybinds, which makes it less of a problem. The majority of games that use keybinds on Roblox don’t.

To answer your question, there is an alternate method, but it does not work for international keyboard layouts (at least from my testing). The BindAction function also allows you to detect key inputs, which seems more like the second question you asked (executing a function after a specific character input), but I can’t find any method that works with international keyboard layouts. If you’re looking to capture text, your best bet would be an invisible TextBox, then forcing capture on it, although that’s a hacky method and comes with its own problems.

If you want proper support for other keyboard layouts, you can make a feature suggestion at #platform-feedback:engine-features.

1 Like