The UserInputService can bind functions to user input via events such as "InputBegan", for example:
01 | local UIS = game:GetService( "UserInputService" ) |
02 | local plr = game.Players.LocalPlayer |
03 | local char = plr.Character |
04 | local hum = char.Humanoid |
06 | function superJump(inputObject, GPE) |
07 | if inputObject.KeyCode = = Enum.KeyCode.U then |
13 | UIS.InputBegan:connect(superJump) |
As for the ContextActionService, it can bind a SET of inputs to a function, additionally it can create GUI buttons on mobile for compatibility.
For example:
01 | local CAS = game:GetService( "ContextActionService" ) |
02 | local plr = game.Players.LocalPlayer |
03 | local char = plr.Character |
04 | local hum = char.Humanoid |
06 | function speedUp(actionName, userInputState, inputObject) |
07 | if userInputState = = Enum.UserInputState.Begin then |
13 | CAS:BindAction( "speedingUp" , speedUp, false , Enum.KeyCode.Y) |
Also, a function bound through BindAction can be fired on all changes of the input's state, whether it began, ended, or changed.
Personally, if I were beginning keyboard input, I would go with the UserInputService for simplicity!
http://wiki.roblox.com/index.php?title=API:Class/UserInputService
http://wiki.roblox.com/index.php?title=API:Class/ContextActionService