Easy key events in tools
#1
Here is some code to make key controls easier to work with in a tool.
This will be placed in a script inside a Tool
[lua]local keys={}
function iskeydown(k)
for i,v in pairs(keys) do
if v==k then return true end
end
return false
end
function keydown(k)
if not iskeydown(k) then
table.insert(keys,k)
end
end
function keyup(k)
if iskeydown(k) then
local ind=0
for i,v in pairs(keys) do
if v==k then ind=i end
end
table.remove(keys,ind)
end
end
link(script.Parent.KeyDown,keydown)
link(script.Parent.KeyUp,keyup)[/lua]

With this code you ca later say
[lua]if iskeydown("KEY HERE") then[/lua]
To see if that key is currently being pressed.
[Image: 5widdh.png]
Siggy by McNoobster!
[Image: loading.gif]
Reply
#2
Cool, thanks a lot.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)