I’m trying to set up customizable keybindings for my game, and they work properly IF the custom keybind is a letter, but if it’s something like LeftAlt
or LeftShift
then for some reason, the GetStringForKeyCode()
method doesn’t return a string for those.
Here’s the function I’m using for keybindings. It works properly except for what I mentioned above:
function InputController.onInputBegan(input, gameProcessed)
if gameProcessed then return end
if input.UserInputType == Enum.UserInputType.Keyboard then
local inputKeyCodeString = userInputService:GetStringForKeyCode(input.KeyCode)
print(inputKeyCodeString, cameraLockKeyCode.Value)
if inputKeyCodeString == cameraLockKeyCode.Value then
cameraLockEvent:Fire()
elseif inputKeyCodeString == targetLockKeyCode.Value then
targetLockEvent:Fire()
end
elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
primaryAttackEvent:Fire()
end
end
The print()
you can see prints out letters just fine when they are pressed for inputKeyCodeString
, but when LeftAlt
or LeftShift
is pressed, it prints an empty string for that value. It prints cameraLockKeyCode.Value
out properly as LeftAlt
, so I don’t know what I’m doing wrong. Again, the events under the if
checks fire properly if the custom keybinding is set to a letter like Q
.