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

is possible to have a two button key bind?

Asked by 6 years ago

I'm trying to make a diagonal animation play when they keys "D" and "W" are pressed at the same time, how would I make that work?

if input1.KeyCode == Enum.KeyCode.W and D then
0
You could make 2 variables on whether W and D are pressed, and have a function to run when they are both true. UgOsMiLy 1074 — 6y

1 answer

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

Yes, you can with UserInputService.

Let's say you have a function called onKeyPress that is connected to UserInputService#InputBegan, then you could do it like this.

local UIS = game:GetService("UserInputService")

local function onKeyPress(input, gameProcessedEvent)
    if (input.KeyCode == Enum.KeyCode.W) and (UIS:IsKeyDown(Enum.KeyCode.D) then
        -- Your code
    end
end

UIS.InputBegan:Connect(onKeyPress)

If the InputBegan event fires, we check if input.KeyCode is the same as Enum.KeyCode.D (The D Button), if it is the same, we use UserInputService#IsKeyDown if another key is pressed down right now, in this case the W Key. If the 2nd key is pressed down too, it executes the code.

(Short disclaimer: I don't know if it fully works) If you need more infos, feel free to reply in the Comments*

0
It worked perfectly, thanks! Revisedy 23 — 6y
Ad

Answer this question