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

How do I know if a key is pressed?

Asked by
P100D 590 Moderation Voter
9 years ago

Also, is there any way to tell how long it is pressed for, and when it is let go?

1
Please search the wiki and this site, before asking a question. Here is the wiki page: http://wiki.roblox.com/index.php?title=KeyDown parkderp1 105 — 9y
0
They're deprecated. What's the new version? P100D 590 — 9y

1 answer

Log in to vote
4
Answered by
parkderp1 105
9 years ago

To find how long it is pressed for you would set a variable to tick() in your KeyDown function like so:

mouse=  --(However you're getting the mouse)

mouse.KeyDown:connect(function(key)
    --Do whatever you want with that key here
    pasttime=tick()
end)

Then in your KeyUp function would set another variable to tick() and subtract the pasttime variable from the variable you just set. Example:

mouse.KeyDown:connect(function(key)
    --Do whatever you want with that key here
    currenttime=tick()
    keytime=currenttime-pasttime
end)

The keytime variable would be the time the key is pressed.

0
Please accept my answer. parkderp1 105 — 9y
Ad

Answer this question