How can i make a two key trigger input

for example i have this script: if inputObject.KeyCode == Enum.KeyCode.Q

how can i make it so it needs Q and E to trigger

2 Likes

Good question. Based on your provided code, I’m assuming you already know of the InputBegan event. One option would be to simply track when either key gets pressed with boolean values, only executing the process if both return true, but UserInputService already does this for you.

Using the IsKeyDown function, you can check if any key is currently being held down. This, combined with InputBegan, should make it fairly easy to detect key combinations:

local key1=Enum.KeyCode.Q
local key2=Enum.KeyCode.E
local uis=game:GetService("UserInputService")

function inputBegan(input)
    --there are two scenarios we're looking for: one where key1 is the most recently
    --pressed and key2 is already down, and one where key2 is the one just pressed
    --and key1 is already down.
    if (input.KeyCode==key1 and uis:IsKeyDown(key2)) or (input.KeyCode==key2 and uis:IsKeyDown(key1)) then
        --both keys are pressed, so you can execute your code here
    end
end

uis.InputBegan:Connect(inputBegan)

Hope this helped! (Also, while it’s not necessary to use here, GetKeysPressed is another useful function.)

9 Likes