Has anybody got the code for detecting the enter key pressed. I've tried all the things on the forums but they just don't do anything.
If someone can help me out that would be appreciated Thanks!
The following code will print something when the R key is pressed.
function onKeyPress(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.R then print("R was pressed") end end game:GetService("UserInputService").InputBegan:connect(onKeyPress)
Basically you'd be using the UserInputService and when InputBegan is fired it'd run OnKeyPress() and then you would check which key was clicked which in this example is 'R' using
if inputObject.KeyCode == Enum.KeyCode.R then
then you'd run your code
This example prints 'R was pressed' when the R key is clicked and prints 'Q was pressed' when the Q key is pressed.
function onKeyPress(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.R then print("R was pressed") elseif inputObject.KeyCode == Enum.KeyCode.Q then print("Q was pressed") end end game:GetService("UserInputService").InputBegan:connect(onKeyPress)
Sourse http://http://wiki.roblox.com/index.php?title=Keyboard_input
The key code pages gives you codes for keys like Enter and Tab
Key Codes http://wiki.roblox.com/?title=API:Enum/KeyCode Hope this helped.
You can use the following to detect for the enter key
local UIS = game:GetService("UserInputService") UIS.InputBegan:Connect(function(input,GPE) if input.KeyCode == Enum.KeyCode.Return then -- do the action here end end
The keycode for enter is 13, it would be used like this
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() Mouse.KeyDown:connect(function(Key) if Key == 13 then --Code end end)
I do not recommend using KeyDown, as it has been deprecated