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

Using the KeyCode UserInput function (when V is pressed)?

Asked by 6 years ago

Does anyone know how to use the new KeyCode API? It's GetKeysPressed, but I don't know how to use it.

I would like it when the letter V is pressed, then I'll add my own code there.

Thanks, -flor

3 answers

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago
local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(key,bool)
   if bool == false then
      if key.KeyCode == Enum.KeyCode.V then
         --do stuff here
      end
   end
end)

Keep in mind this has to be done from a local script.

0
It this FilteringEnabled? I'm still trying to learn FilteringEnabled. Florian27 76 — 6y
0
The code doesn't seem to work, I put a print statement in the line of code and nothing happened. I used a local script in Workspace. Florian27 76 — 6y
0
I'll sort this out for you, bare with me. StoleYourClothes 105 — 6y
0
Alright Florian27 76 — 6y
0
Local script only run from places that are independent to each player, such as their gui. Try putting it in StarterGui. mattscy 3725 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(key, bool)
bool = false
   if bool == false then
      if key.KeyCode == Enum.KeyCode.V then
         -- do stuff here
         bool = true
      end
   end
end)
0
Try that, if it doesn't work, please let me know. StoleYourClothes 105 — 6y
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Both of ya'll are wrong. This is the correct way,

Here's the link: http://wiki.roblox.com/index.php?title=Keyboard_input

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

game:GetService("UserInputService").InputBegan:connect(onKeyPress)
0
We are not wrong, we are just using a different method / coding differently. StoleYourClothes 105 — 6y

Answer this question