Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What are the ASCII values for arrow keys?

I can't seem to find them.

3 answers

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

1 comment

0

This also works too.

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.