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

How do you detect key presses?

Asked by 11 years ago

Trying to make a custom camera that is moved with the WASD keys

3 answers

Log in to vote
1
Answered by
emite1000 335 Moderation Voter
11 years ago

Use the KeyDown Event. You can define WASD using the second parameter.

Syntax: KeyDown (String, key).

Ad
Log in to vote
0
Answered by 11 years ago

Inside a script inside a hopperbin:

1function onSelected(mouse)
2    function onKeyDown(key)
3        print(key) -- That's the key you pressed.
4    end
5    mouse.KeyDown:connect(onKeyDown)
6end
7script.Parent.Selected:connect(onSelected)

Hope that helps!

Log in to vote
0
Answered by 11 years ago

If you were trying to make a custom camera or a 'Probe' as some would say, you could always use Workspace.CurrentCamera.Focus or Workspace.CurrentCamera.CoordinateFrame (focus for in game coordinate frame for nil) But in this case, the one I am giving you is detecting which key is being pressed in the movement category, and if it matches it then it prints which way your going.

01s = game.Players.LocalPlayer
02m = s:GetMouse()
03m.KeyDown:connect(function(a)
04if a:lower() == "a" then
05print'left'
06elseif a:lower() == "s" then
07print'down'
08elseif a:lower() == "w" then
09print' up'
10elseif a:lower() == "d" then
11print'right'
12end
13end)

Answer this question