How to use modifier keys

Hello Devforum, I can’t seem to figure out how to use keycode modifiers, such as a key combination like Shift + 1. This is probably a quick and easy question but any help is appreciated.

Like this?

local UserInput = game:GetService("UserInputService")
if UserInput:IsKeyDown(Enum.KeyCode.LeftShift) and UserInput:IsKeyDown(Enum.KeyCode.One) then

end
1 Like

Yeah I think that’s it, will try in a moment.

For more info, @lovableschoolgirl’s solution will only trigger once. The way to get around this is to listen for the second input (1) and do a check whether the first key (1) is also being held down.

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(inputObject, gp)
    if gp then return end

    if inputObject.KeyCode == Enum.KeyCode.One and UIS:IsKeyDown(Enum.KeyCode.LeftShift) then
        print("Triggered keybind Shift + 1")
    end
end)

What does gp do then? (gsjdngjs)

gp, also known as gameprocessed is a parameter to UIS.InputBegan (and some other UIS events) which tells you if the player is “focused” on the game. If it is true, it means that the player is chatting or is in the menu or tabbed out and vel sim. By returning when gp is true, it means that it won’t process it if the player isn’t actually playing.

I’m having some troubles here, on some of them it just does nothing at all.
For example on the second keybind. (It does this on the 4th too)

UIS.InputBegan:Connect(function(inputObject, gp)
	if gp then return end

	if inputObject.KeyCode == Enum.KeyCode.Two and UIS:IsKeyDown(Enum.KeyCode.LeftShift) then
		print("Triggered keybind Shift + 2")
		script.Parent.Sound:Play()
		rs.FW2:FireServer()
		script.Parent.TextColor3 = Color3.new(1, 0.376471, 0.388235)
		wait(0.1)
		script.Parent.TextColor3 = Color3.new(0,0,0)
	end
end)

In all honesty this could be a stupid mistake but I can’t see it.

You can use an if parameter to check if both keys are held down, simply by:

local UIS = game:GetService("UserInputServce")

local key1 = Enum.KeyCode.LeftShift
local key2 = Enum.KeyCode.One

while task.wait() do
    if not UIS:GetFocusedTextBox() then
        if UIS:IsKeyDown(key1) and UIS:IsKeyDown(key2) then
            print("completed")
        end
    end
end

Besides a type detection, there is no proper way to detect a key being held down, so it has to be looped with a short delay.

The reason why your .InputBegan event didn’t work is because it’s trying to detect 2 keys being clicked at the exact same time, there is no breath period. I would just detect when the key is held down.

Strange, I tried your code and it works for the keys that work with the other script, but not with Shift + 2/4(the broken ones)

You can add multiple checks. Like this:

local UIS = game:GetService("UserInputServce")

while task.wait() do
    if not UIS:GetFocusedTextBox() then
        if UIS:IsKeyDown(Enum.KeyCode.LeftShift) then
            if UIS:IsKeyDown(Enum.KeyCode.One) then
                print("1")
            elseif UIS:IsKeyDown(Enum.KeyCode.Two) then
                print("2")
            elseif UIS:IsKeyDown(Enum.KeyCode.Three) then
                print("3")
            end
        end
    end
end

You can add as many as you want, or change the modifier keys.