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

I don't understand how to access keyboard input?

I get that its something like



function KeyInput()
if Enum.UserinputType.Keybaord then
end)





But I can't provide a script to something I can't understand

 can someone just simply explain how to access key input?

I just want an explanation.

so if key y or anything else was pressed then
print ( This key was pressed)

3 answers

use userinputservice or keydown if its for roblox(keydown is deprecated)

local mouse = game.Player.LocalPlayer:GetMouse() mouse.Keydown:Connect(function(key) --Happening end)

local db = false -- debounce since it's usually necessary
local uis = game:GetService("UserInputService") -- get userinputservice
	uis.InputBegan:connect(function(input, gp) -- when a input from any device happens
--input is the argument for the input object that was activated, gp is gameprocessed.
		if gp then -- if we're in the pause menu or chatting or something where you don't want to pick up a key press, end the function.
			return
		else
			if (input.UserInputType == Enum.UserInputType.Keyboard) and not db then -- if we're on keyboard and debounce is false.
				if (input.KeyCode == Enum.KeyCode.X) then -- if our input object was the X key.
					db = true -- debounce is now true.
					-- do anything
					wait(3) -- our cooldown for the function to trigger
					db = false -- let the function trigger once more
				end
			end
		end
	end)

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