Hey Developers,
I have been trying multiple options but I haven’t had any success in detecting multiple Key Input’s. My aim is for my script to detect a Ctrl+G input to trigger something.
Hey Developers,
I have been trying multiple options but I haven’t had any success in detecting multiple Key Input’s. My aim is for my script to detect a Ctrl+G input to trigger something.
You can set a variable called “HoldingControl” and set it to true when keyinput is control, and set it to false when keyoutput is control. When you have a keyinput of G, you can check whether or not the variable HoldingControl is true, and if it’s true, then it detects Ctrl+G, otherwise, Ctrl is not being held before G. Let me know if you need code to help you out.
Could you provide a code example?
local UserInputService = game:GetService("UserInputService")
local HoldingControl = false
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.LeftControl then
HoldingControl = true
elseif input.KeyCode == Enum.KeyCode.G and HoldingControl then -- Detects Ctrl + G
--Code Here for Ctrl + G
end
end
end)
UserInputService.InputEnded:Connect(function(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.LeftControl then
HoldingControl = false
end
end
end)
Even better: store all held keys so you can get an accurate representation of what key is being pressed if you ever want to have more modified keybinds.
I know this thread is a bit old… but would you or anyone else have an example of how to store the keys for a larger bind setup?
I am primarily needing this for a custom game pad setup.
Eek. When I made this post I forgot :IsKeyDown()
and :IsGamepadButtonDown()
existed. Use those instead. If you want all keys, use :GetKeysPressed()
.