04-10-2011, 03:32 AM
(This post was last modified: 04-10-2011, 03:32 AM by equalFahun.)
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.
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]](http://i51.tinypic.com/5widdh.png)
Siggy by McNoobster!
![[Image: loading.gif]](http://buildism.net/game/loading.gif)