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

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

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

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.

5 comments

0

It this FilteringEnabled? I'm still trying to learn FilteringEnabled.

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.

0

I'll sort this out for you, bare with me.

0

Alright

0

Local script only run from places that are independent to each player, such as their gui. Try putting it in StarterGui.

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)

1 comment

0

Try that, if it doesn't work, please let me know.

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)

1 comment

0

We are not wrong, we are just using a different method / coding differently.

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