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

is possible to have a two button key bind?

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

1 comment

0

You could make 2 variables on whether W and D are pressed, and have a function to run when they are both true.

1 answer

✓ Accepted answer

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*

1 comment

0

It worked perfectly, thanks!

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