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 10 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
10 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 10 years ago

Inside a script inside a hopperbin:

function onSelected(mouse)
    function onKeyDown(key)
        print(key) -- That's the key you pressed.
    end
    mouse.KeyDown:connect(onKeyDown)
end
script.Parent.Selected:connect(onSelected)

Hope that helps!

Log in to vote
0
Answered by 10 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.


s = game.Players.LocalPlayer m = s:GetMouse() m.KeyDown:connect(function(a) if a:lower() == "a" then print'left' elseif a:lower() == "s" then print'down' elseif a:lower() == "w" then print' up' elseif a:lower() == "d" then print'right' end end)

Answer this question