The title explains it self, I’ve tried using GetKeysDown it returns only one key being held, tried Input began parameter it returns only one.
Any help is really appreciated. (I’ll not use Plugin Action though)
My Code:
UIS.InputBegan:Connect(function(Input, Proccessed)
for _, v in ipairs(GroupedItems) do
if v.ShortCutKeyTable and v.OtherShortCutKeyTable then
print(UIS:IsKeyDown(v.ShortCutKeyTable) , UIS:IsKeyDown(v.OtherShortCutKeyTable))
if UIS:IsKeyDown(v.ShortCutKeyTable) and UIS:IsKeyDown(v.OtherShortCutKeyTable) then
end
end
end
end)
The InputBegan event only fires for one input at a time, so you won’t be able to detect multiple keys being held down simultaneously using that event alone. Instead, you can use the InputService to keep track of which keys are currently being held down.
Here’s an example implementation using the InputService:
local InputService = game:GetService("UserInputService")
local heldKeys = {}
InputService.InputBegan:Connect(function(input, processed)
if not processed then
if input.UserInputType == Enum.UserInputType.Keyboard then
heldKeys[input.KeyCode] = true
end
end
end)
InputService.InputEnded:Connect(function(input, processed)
if not processed then
if input.UserInputType == Enum.UserInputType.Keyboard then
heldKeys[input.KeyCode] = nil
end
end
end)
while true do
if heldKeys[Enum.KeyCode.LeftControl] and heldKeys[Enum.KeyCode.A] then
print("Control + A is being held down")
end
wait()
end
In this example, we’re using a heldKeys table to keep track of which keys are currently being held down. We update this table whenever a UserInputType of Keyboard is detected in the InputBegan and InputEnded events.
Then, in a loop, we check whether heldKeys contains the desired key combination (Enum.KeyCode.LeftControl and Enum.KeyCode.A in this case). If it does, we execute the desired action (printing a message to the console in this example).
Note that this loop should not be used in production code, as it can potentially cause performance issues. Instead, you should use this logic within a specific context where you need to detect the key combination.
What I’m doing is creating a table with the user info so I can’t use UserInputService rather I wanna wait for an event for the user not use a while loop as it’s a bad practice and then I’ll check if the user actually pressed the buttons. The issue is detecting which keys they have pressed (it returns only once and returns other false)
local Test = {
{
TurnInto = "Model"
ShortCut = "E"
SecondShortCut = "F"
}
}
@ItsMeKlc As I’ve said I don’t want to use Plugin Actions as they require the user to create their own shortcuts (unless I’m missing something since I’m not familiar with Plugin Action) which is annoying. Rather I wanna detect their input themselves.
I see, in that case, you can use the UserInputService to detect key presses outside of a while loop. Here’s an example implementation that listens for a key press and then checks if the key combination matches the one you’re looking for:
local UserInputService = game:GetService("UserInputService")
local test = {
{
TurnInto = "Model",
ShortCut = Enum.KeyCode.E,
SecondShortCut = Enum.KeyCode.F,
},
}
UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if gameProcessedEvent then
return
end
-- Check if the input is a keyboard key press
if input.UserInputType == Enum.UserInputType.Keyboard then
-- Check if the input matches the desired key combination
for _, shortcut in ipairs(test) do
if input.KeyCode == shortcut.ShortCut and UserInputService:IsKeyDown(shortcut.SecondShortCut) then
print("Key combination detected: " .. shortcut.ShortCut.Name .. " + " .. shortcut.SecondShortCut.Name)
-- Execute the desired action here
return
end
end
end
end)
In this example, we’re using the InputBegan event to listen for a key press. When a key press is detected, we check if the input matches the desired key combination by looping through the test table. If the input matches the desired combination, we execute the desired action (printing a message to the console in this example).
Note that we’re also using the IsKeyDown method of the UserInputService to check if the second key in the combination is being held down. This allows us to detect key combinations where both keys are being held down simultaneously.