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

What should I use now that KeyDown is deprecated?

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

4 comments

2

UserInputService! ~~~ too tired to answer

0

Oh, ok. I think I should do more research on that service.

1

Can i use that service in plugins?

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.

2 answers

✓ Accepted answer
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)

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

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