Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

What are the ASCII values for arrow keys?

Asked by 9 years ago

I can't seem to find them.

3 answers

Log in to vote
2
Answered by
2eggnog 981 Moderation Voter
9 years ago

Here's the wiki page for special characters: http://wiki.roblox.com/index.php?title=Special_Characters. The arrows are ASCII values 17-20.

0
Thank you. hievery1 70 — 9y
Ad
Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

We can find them ourselves using a really simple script. No need to look them up at all.

local m = game.Players.LocalPlayer:GetMouse();

m.KeyDown:connect(function(e)
    print(e:byte());
end
);

Left: 20

Down: 18

Right: 19

Up: 17

0
This also works too. hievery1 70 — 9y
Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

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:

local uis = Game:GetService("UserInputService")

uis.InputBegan:connect(function(inst) --KeyDown
    if inst.UserInputType == Enum.UserInputType.Keyboard then
        if inst.KeyCode == Enum.KeyCode.Left then
            print("Left arrow pressed")
        elseif inst.KeyCode == Enum.KeyCode.Right then
            print("Right arrow pressed")
        end --And so on.
    end
end
uis.InputEnded:connect(function(inst) --KeyUp
    --you get the idea
end

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.

Answer this question