While this doesn't answer your question, I would suggest that you use the UserInputService to bind keys to functions, rather than connecting the KeyDown event. You'll never run into problems like this (having to look up specific keycodes), and you'll never have to worry about keys sharing keycodes, or certain keycodes for KeyUp or KeyDown being reserved by ROBLOX.
This runs in a LocalScript:
01 | local uis = Game:GetService( "UserInputService" ) |
03 | uis.InputBegan:connect( function (inst) |
04 | if inst.UserInputType = = Enum.UserInputType.Keyboard then |
05 | if inst.KeyCode = = Enum.KeyCode.Left then |
06 | print ( "Left arrow pressed" ) |
07 | elseif inst.KeyCode = = Enum.KeyCode.Right then |
08 | print ( "Right arrow pressed" ) |
12 | uis.InputEnded:connect( function (inst) |
Those two events also fire on mouse clicks, and there is a third, InputChanged
that fires when the mouse moves, or the scrollwheel is scrolled.
Additionally, there are events in the UserInputService that allow you to bind functions to Touch controls, such as for an iPad.