romero126
Joined: 24 Dec 2005 Posts: 200
|
Posted: Tue Dec 27, 2005 10:53 pm Post subject: (Code of the day) Key Up/KeyDown Triggered Events. |
|
|
Are you tired of trying to figure out which key isnt currently being pushed down and keys not being pushed down? To allow for multiple button pressed events? Look no farther! Here is a simple process to add event driven key commands to your LUA code!
Taken from input.lua
| Code: |
-- Coded by romero126
GlassEyeInput = {
["KeyList"] = { }
}
table.insert(GlassEyeInput["KeyList"], {Controls.selectMask, "Select", nil})
table.insert(GlassEyeInput["KeyList"], {Controls.startMask, "Start", nil})
table.insert(GlassEyeInput["KeyList"], {Controls.upMask, "Up", nil})
table.insert(GlassEyeInput["KeyList"], {Controls.rightMask, "Right", nil})
table.insert(GlassEyeInput["KeyList"], {Controls.downMask, "Down", nil})
table.insert(GlassEyeInput["KeyList"], {Controls.leftMask, "Left", nil})
table.insert(GlassEyeInput["KeyList"], {Controls.ltriggerMask, "LTrigger", nil})
table.insert(GlassEyeInput["KeyList"], {Controls.rtriggerMask, "RTrigger", nil})
table.insert(GlassEyeInput["KeyList"], {Controls.triangleMask, "Triangle", nil})
table.insert(GlassEyeInput["KeyList"], {Controls.circleMask, "Circle", nil})
table.insert(GlassEyeInput["KeyList"], {Controls.crossMask, "Cross", nil})
table.insert(GlassEyeInput["KeyList"], {Controls.squareMask, "Square", nil})
table.insert(GlassEyeInput["KeyList"], {Controls.homeMask, "Home", nil})
table.insert(GlassEyeInput["KeyList"], {Controls.holdMask, "Hold", nil})
table.insert(GlassEyeInput["KeyList"], {Controls.noteMask, "Note", nil})
function GlassEyeInput:CheckInput(key)
result = nil
for k, v in GlassEyeInput["KeyList"] do
if (key:buttons() & v[1] > 0) then
if (not v[3]) then
v[3] = 1
if (not result) then result = { } end
result[v[2]] = 1
end
else
if (v[3]) then
if (not result) then result = { } end
result[v[2]] = 0
v[3] = nil
end
end
end
return result
end
|
This allows a user to get input from on an event basis.
See:
| Code: |
-- Coded by romero126
if (GlassEyeInput) then
local check = GlassEyeInput:CheckInput(key)
if (check) then
for k,v in check do
if (k == "Start") and (v == 0) then
print("You lifted your finger on the start key")
end
if (k == "Start") and (v == 1) then
print("You pressed your finger on the start key")
end
end
end
end
|
Please note glass eye is a current project of mine. With standard libraries for an event driven based system.
Please give props to the rightfull owner in your code.
Comments, questions Concerns? Let me know!
Last edited by romero126 on Thu Jan 05, 2006 7:36 am; edited 1 time in total |
|