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

I don't understand how to access keyboard input?

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

Ad
Log in to vote
0
Answered by
gloveshun 119
4 years ago

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

Log in to vote
0
Answered by
Gojinhan 353 Moderation Voter
4 years ago
Edited 4 years ago
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)

Answer this question