forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

(Code of the day) Key Up/KeyDown Triggered Events.

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
romero126



Joined: 24 Dec 2005
Posts: 200

PostPosted: Tue Dec 27, 2005 10:53 pm    Post subject: (Code of the day) Key Up/KeyDown Triggered Events. Reply with quote

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
Back to top
View user's profile Send private message
modsyn



Joined: 27 Sep 2005
Posts: 28

PostPosted: Thu Jan 05, 2006 5:20 am    Post subject: Reply with quote

nice! very helpful stuff. i hate writing controls code. this might make it simpler.
Back to top
View user's profile Send private message
romero126



Joined: 24 Dec 2005
Posts: 200

PostPosted: Thu Jan 05, 2006 7:37 am    Post subject: Reply with quote

Edited because of a bug I noticed.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group