I haven't dabbled far from using events on functions I already know, so all I really need is an example of IsKeyDown. Any example.
Thanks.
I haven't dabbled far from using events on functions I already know, so all I really need is an example of IsKeyDown. Any example.
Thanks.
You can use the UserInputService with the method GetKeysPressed which returns a list of current InputObject.
This an example to show how it can be used, is also must be a local script:-
local inpServ = game:GetService('UserInputService') -- gets the service
function isKeyDown(key)
for i,v in pairs(inpServ:GetKeysPressed()) do
if v.KeyCode == key then return true end
end
return false -- no keys found
end
function isMultiKeyDown(keys)
local num = 0 -- keydown counter
for i,v in pairs(inpServ:GetKeysPressed()) do
for i2, v2 in pairs(keys) do -- probably should check for multiples of the same key
if v.KeyCode == v2 then num = num + 1 end
end
end
return num == #keys -- just return true of false
end
while true do
print("multiple", isMultiKeyDown({Enum.KeyCode.A, Enum.KeyCode.S}))
print("single", isKeyDown(Enum.KeyCode.A))
wait(3)
end
Hope this helps
This discussion is preserved as it was. New answers, comments, and votes are closed.