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

What should I use now that KeyDown is deprecated?

Asked by 8 years ago

The Wiki says KeyDown is deprecated, so what do I use now?

2
UserInputService! ~~~ too tired to answer YellowoTide 1992 — 8y
0
Oh, ok. I think I should do more research on that service. xxracerdudexx 75 — 8y
1
Can i use that service in plugins? xxracerdudexx 75 — 8y
1
UserInputService only runs in LocalScripts. LocalScripts do not run in plugins. Therefore, do /not/ use UserInputService for plugins. For your purposes, KeyDown is perfectly OK. XAXA 1569 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago
You could use this 
function onKeyPress(actionName, userInputState, inputObject)
    if userInputState == Enum.UserInputState.Begin then
        print("R was pressed")
    end
end

game.ContextActionService:BindAction("keyPress", onKeyPress, false, Enum.KeyCode.R)
-- The above line could also been written as:
-- game.ContextActionService:BindAction("keyPress", onKeyPress, false, "r")


Or this 


function onKeyPress(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.R then
        print("R was pressed")
    end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)
Ad
Log in to vote
0
Answered by 8 years ago

UserInputService is good, like Yellow said, so go ahead and learn about that service.

Answer this question