2DWorlds Forums
Easy key events in tools - Printable Version

+- 2DWorlds Forums (http://2dworlds.buildism.net/forum)
+-- Forum: 2DWorlds (http://2dworlds.buildism.net/forum/forumdisplay.php?fid=4)
+--- Forum: 2DWorlds Discussion (http://2dworlds.buildism.net/forum/forumdisplay.php?fid=10)
+---- Forum: Tutorials and Guides (http://2dworlds.buildism.net/forum/forumdisplay.php?fid=20)
+---- Thread: Easy key events in tools (/showthread.php?tid=2666)



Easy key events in tools - toast - 04-10-2011

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.


RE: Easy key events in tools - Ice - 04-10-2011

Cool, thanks a lot.