I’m Youf and i’m currently making a typing game. Everything is going well, except that players that have AZERTY keyboard need to press another key for it to be correct. Example: Q for A, Z for W
It’s like they had a QWERTY keyboard, which is pretty disturbing.
I’ve been struggling to solve this and i read plenty of posts on the DevForum. Unfortunately, none of them really answers my question.
SCRIPT:
UIS.InputBegan:Connect(function(input, IsTyping)
if IsTyping then return end
for _, key in pairs(script.Parent.Keys:GetChildren()) do
if key:IsA("ImageButton") then
if input.KeyCode == Enum.KeyCode[key.Name] then
-- code
end
end
end
end)
I don’t think there’s a Roblox-default solution for this. You’ll just have to make a game setting where you can configure your keyboard layout and then have the script convert to the appropriate ones.
As far as I’m aware, there isn’t really a function to indicate that. What you can do is either ask the user what keyboard they are using, or use the UserInputService:GetStringForKeyCode() function, which is meant to return a string representation of what is actually pressed. As stated on the documentation page;
So the usage of the GetStringForKeyCode() will provide useful. Regardless of which method you choose, you’ll have to make an AZERTY to QWRTY keycode converter.
I don’t really know how i can explain, but i managed to make it work. When you press A it becomes Q and when you press Z it becomes W. For some unknown reason the “M” key doesn’t work on AZERTY, even tho your pressing on “,”. If you have any solution to this, please let me know. You can find a video below to help you understand.
When using Roblox with a non-QWERTY keyboard layout, key codes are mapped to equivalent QWERTY positions. For example, pressing A on an AZERTY keyboard results in Keycode.Q. This mapping can lead to mismatched information on game help menus. For example, “Press M to open Map” is inaccurate on an AZERTY keyboard; it would need to be “Press ? to open Map”, which is in the same position as M on QWERTY. This just doesn’t work with M for some reason.
The code:
UIS.InputBegan:Connect(function(input, IsTyping)
--if IsTyping then return end
for _, key in pairs(script.Parent.Keys:GetChildren()) do
if key:IsA("ImageButton") then
if input.KeyCode == Enum.KeyCode[key.Name] then
key.ImageColor3 = Color3.fromRGB(158, 157, 159)
for i, letter in pairs(script.Parent.Parent.WordDisplay.LetterManager:GetChildren()) do
if letter:IsA("Frame") then
if letter:FindFirstChild("Text") then
if letter:FindFirstChild("Text").Text == UIS:GetStringForKeyCode(Enum.KeyCode[key.Name]) then
-- code
end
end
end
end
end
end
end
end)
If you’re still confused about what my problem is, you can play my game and see by yourself. When you play with QWERTY everything goes well. But ones you swish to AZERTY, the M-key doesn’t work anymore.
The issue is probably because of the special characters. I don’t know the specifics of AZERTY keyboards, but as the documentation stated, M results in ?, so when you use the GetStringForKeyCode() function, it returns the string “?”. Of course, there is no KeyCode such as “?”, the actual KeyCode is Enum.KeyCode.Question. You’ll need to make a table for translating special characters into their Enum names. Since you are using only letters, this shouldn’t be too difficult, just put all the keys that aren’t working in the table, check if the current string key exists in that table, and if it does, use that instead.
Unfortunately, that’s not the problem here. :GetStringForKeyCode() is useless for defining keyboard layout, as it doesn’t work for M . The real problem is that there is nothing defined for M (in AZERTY) for QWERTY.
Let’s demonstrate with a couple examples:
AZERTY= A, QWERTY = Q
AZERTY= Z, QWERTY = W
AZERTY= M, QWERTY = nothing
This leads to the following problem; if an AZERTY player presses M, it can’t be defined in QWERTY. By using :GetStringForKeyCode() it will define as ,. That’s why it’s useful for the example i gave previously,
Example
For example, “Press M to open Map” is inaccurate on an AZERTY keyboard; it would need to be “Press , to open Map”, which is in the same position as M on QWERTY.
but useless for keyboard layouts.
I don’t think the real problem can be solved using :GetStringForKeyCode(). This is pretty disturbing as i saw other typing games doing it. This one for example: Type Race! - Roblox . It automatically puts the correct KeyCodes depending on your keyboard layout. I guess i’ll just make it so that you have to use QWERTY for now. I hope finding a solution later on.
I really appreciate your help. I learned a couple interesting things thanks to you.
Hey there. So, I did a bunch of digging around, and it seems like there isn’t really much you can do. I did find one post that said that you can use Mouse.KeyDown instead, but it looks like its been depreciated and now it returns what UserInputService would return as well. The only thing I can think of is having some type of invisible TextBox that you force the players to type on and detect key input from there. Maybe @haz3mn might have some feedback on ways you can go around this, but unfortunately this is a dead end for me. I do really wish I could help out more, but that’s as far as I know.