Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Code update by Bystander on 8/28/2011
- ------------------------------------------------------------------------------------------------------------
- POLL_DELAY = 25 -- Sleep time after each poll (beware of number below 25)
- POLL_FAMILY = "kb" -- The device polling will take place on. Prefered to not be on macroed device.
- -- KB_EVENTS = true -- If you don't have a logitech keyboard, make this false/nil or comment out
- -- LHC_EVENTS = true -- if you don't have a logitech left handed controller, make this false/nil or comment out
- ------------------------------------------------------------------------------------------------------------
- DEVICE = "kb"
- color = 1
- mouse = true
- button = 1
- speed = POLL_DELAY -- this should alwasy be equal or larger than POLL_DELAY
- disco = 0
- mouseRepeatTime = 5000 -- in milliseconds
- mouseDelay = 250
- mousePressTime = 25
- function _onActivation(event, arg, family)
- --
- -- ADD ANY START UP ROUTINES HERE
- --
- -- POLL:setMKeyModifier( "default", "mb5", "mb4", "lhc" ) -- Allows the use of Modifiers to change M pages
- ctDiscoColors1 = CoThread:new(discoColors1)
- ctDiscoColors2 = CoThread:new(discoColors2)
- ctRandomColors = CoThread:new(randomColors)
- ctRepeatMouse = CoThread:new(repeatMouse)
- end
- function _OnEvent(event, arg, family)
- --
- -- ADD EVENT FUNCTIONALITY HERE
- --
- if (event == "G_PRESSED" and arg == 1 and GetMKeyState(DEVICE) == 1) then
- ClearLCD()
- if color == 1 then
- ctRandomColors:stop() -- stops randomColors if it was running()
- SetBacklightColor(255,0,0,DEVICE)
- color = 2
- OutputLCDMessage("Color changed to: Red", 2000)
- elseif color == 3 then
- SetBacklightColor(0,0,255,DEVICE)
- color = 4
- OutputLCDMessage("Color changed to: Blue", 2000)
- elseif color == 2 then
- SetBacklightColor(0,255,0,DEVICE)
- color = 3
- OutputLCDMessage("Color changed to: Green", 2000)
- elseif color == 4 then
- color = 5
- OutputLCDMessage("Color changed to: Fading", 2000)
- ctDiscoColors1:start() -- starts discoColors
- elseif color == 5 then
- ctDiscoColors1:stop()
- color = 6
- OutputLCDMessage("Color changed to: Blinking", 2000)
- ctDiscoColors2:start() -- starts discoColors
- elseif color == 6 then
- ctDiscoColors2:stop() -- stops discoColors
- color = 1
- OutputLCDMessage("Color changed to: Random", 2000)
- ctRandomColors:start() -- starts randomColors
- end
- end -- line 28
- if (event == "G_PRESSED" and arg == 3 and disco == 1) then
- speed = speed-25
- OutputLCDMessage("Speed decreased: " .. speed, 2000)
- if speed < POLL_DELAY then -- if speed is 0 or less, the program will not reliquish control
- speed = POLL_DELAY
- end
- end
- if (event == "G_PRESSED" and arg == 6 and disco == 1) then
- OutputLogMessage("speed\n")
- OutputLCDMessage("Speed increased: " .. speed, 2000)
- speed = speed+25
- end
- if (event == "G_PRESSED" and arg == 5) then
- if (button < 5) then
- button = button + 1
- OutputLCDMessage("Mousebutton changed too: " .. button, 2000)
- else
- button = 1
- OutputLCDMessage("Mousebutton changed too: " .. button, 2000)
- end
- end
- if (event == "G_PRESSED" and arg == 2) then
- if (mouse) then
- ctRepeatMouse:start()
- mouse = false
- else
- ctRepeatMouse:stop()
- mouse = true
- end
- end
- ctDiscoColors1:run()
- ctDiscoColors2:run() -- this will run discoColors as long as it hasn't finished or been stopped with :stop()
- ctRandomColors:run() -- this will run randomColors as long as it hasn't finished or been stopped with :stop()
- ctRepeatMouse:run()
- end
- function repeatMouse(ct)
- while true do
- PressMouseButton(button)
- log("PressMouseButton\n")
- ct:sleep(mousePressTime)
- ReleaseMouseButton(button)
- ct:sleep(mouseDelay)
- end
- end
- function randomColors(ct)
- while true do
- disco = 1
- SetBacklightColor(math.random(0,255),math.random(0,255),math.random(0,255),DEVICE)
- ct:sleep(speed)
- if color ~= 1 then -- if color = 1 it'll continue to loop as before
- disco = 0
- break
- end
- end
- end
- function discoColors1(ct)
- while true do
- disco = 1
- for i = 0, 255, 15 do
- SetBacklightColor(i,0,255,DEVICE)
- -- OutputLogMessage("Red: %i, Green: %i, Blue: %i\n", i, 0, 255)
- ct:sleep(speed)
- end
- -- now to red
- for i = 255, 0, -15 do
- SetBacklightColor(255,0,i,DEVICE)
- -- OutputLogMessage("Red: %i, Green: %i, Blue: %i\n", 255, 0, i)
- ct:sleep(speed)
- end
- -- now to green-red
- for i = 0, 255, 15 do
- SetBacklightColor(255,i,0,DEVICE)
- -- OutputLogMessage("Red: %i, Green: %i, Blue: %i\n", 255, i, 0)
- ct:sleep(speed)
- end
- -- now to green
- for i = 255, 0, -15 do
- SetBacklightColor(i,255,0,DEVICE)
- -- OutputLogMessage("Red: %i, Green: %i, Blue: %i\n", i, 255, 0)
- ct:sleep(speed)
- end
- -- now to green-blue
- for i = 0, 255, 15 do
- SetBacklightColor(0,255,i,DEVICE)
- -- OutputLogMessage("Red: %i, Green: %i, Blue: %i\n", 0, 255, i)
- ct:sleep(speed)
- end
- -- back to blue
- for i = 255, 0, -15 do
- SetBacklightColor(0,i,255,DEVICE)
- -- OutputLogMessage("Red: %i, Green: %i, Blue: %i\n", 0, i, 255)
- ct:sleep(speed)
- end
- -- done
- if color ~= 5 then -- if color == 5 it will continue to loop as before
- disco = 0
- break
- end
- end
- end
- function discoColors2(ct)
- while true do
- disco = 1
- for i = 0, 255, 15 do
- SetBacklightColor(i,0,255,DEVICE)
- -- OutputLogMessage("Red: %i, Green: %i, Blue: %i\n", i, 0, 255)
- ct:sleep(speed)
- SetBacklightColor(0,0,0,DEVICE)
- ct:sleep(speed)
- end
- -- now to red
- for i = 255, 0, -15 do
- SetBacklightColor(255,0,i,DEVICE)
- -- OutputLogMessage("Red: %i, Green: %i, Blue: %i\n", 255, 0, i)
- ct:sleep(speed)
- SetBacklightColor(0,0,0,DEVICE)
- ct:sleep(speed)
- end
- -- now to green-red
- for i = 0, 255, 15 do
- SetBacklightColor(255,i,0,DEVICE)
- -- OutputLogMessage("Red: %i, Green: %i, Blue: %i\n", 255, i, 0)
- ct:sleep(speed)
- SetBacklightColor(0,0,0,DEVICE)
- ct:sleep(speed)
- end
- -- now to green
- for i = 255, 0, -15 do
- SetBacklightColor(i,255,0,DEVICE)
- -- OutputLogMessage("Red: %i, Green: %i, Blue: %i\n", i, 255, 0)
- ct:sleep(speed)
- SetBacklightColor(0,0,0,DEVICE)
- ct:sleep(speed)
- end
- -- now to green-blue
- for i = 0, 255, 15 do
- SetBacklightColor(0,255,i,DEVICE)
- -- OutputLogMessage("Red: %i, Green: %i, Blue: %i\n", 0, 255, i)
- ct:sleep(speed)
- SetBacklightColor(0,0,0,DEVICE)
- ct:sleep(speed)
- end
- -- back to blue
- for i = 255, 0, -15 do
- SetBacklightColor(0,i,255,DEVICE)
- -- OutputLogMessage("Red: %i, Green: %i, Blue: %i\n", 0, i, 255)
- ct:sleep(speed)
- SetBacklightColor(0,0,0,DEVICE)
- ct:sleep(speed)
- end
- -- done
- if color ~= 6 then -- if color == 5 it will continue to loop as before
- disco = 0
- break
- end
- end
- end
- --------------------------------------------------------------------------------------------------------
- --------------------------------------------------------------------------------------------------------
- --
- -- NOTHING BELOW HERE NEEDS TO BE ALTERED
- --
- --------------------------------------------------------------------------------------------------------
- --------------------------------------------------------------------------------------------------------
- -- function Type(v) -- returns what type of object v is. It works with my objects as well
- -- function log(...) -- MessageLogOutput(...)
- -- function typeString(string,delay) -- will type out the string with a Sleep(delay) between keys
- --------------------------------------------------------------------------------------------------------
- --------------------------------------------------------------------------------------------------------
- -- function CoThread:new(f) f - function(coThread,...) coThread is the controlling CoThread
- -- function CoThread:recreate() kill existing coroutine and recreate
- -- function CoThread:create() creates coroutine
- -- function CoThread:isDead() true if coroutine is dead or nil/false
- -- function CoThread:run(...) run coroutine with variables don't include mt
- -- function CoThread:kill() kill coroutine
- -- function CoThread:yield() use in function(coThread,...) to yield
- -- function CoThread:sleep(Milliseconds) use in function(coThread,...) to sleep for Milliseconds
- -- function CoThread:start() does the same thing as recreate()
- -- function CoThread:stop() does the same thing as kill()
- -- function CoThread:isFinished() same as isDead()
- --------------------------------------------------------------------------------------------------------
- --------------------------------------------------------------------------------------------------------
- -- function Poll:new(family, delay) delay is sleep time between polls
- -- function Poll:run(event, arg, family) handles events and performs the polling as long as it's running
- -- function Poll:setMKeyModifier( m1, m2, m3, family ) Allows the use of Modifiers to change M pages
- -- function Poll:start() turn on polling
- -- function Poll:stop() stop polling
- -- function Poll:_press() NOT TO BE USED
- -- function Poll:release() NOT TO BE USED
- -- function Poll:setMKeyState(MKeyState) NOT TO BE USED
- ------------------------------------------------------------------------------------------------------------
- function OnEvent(event, arg, family)
- -- POLLING INITIATED HERE
- _GetRunningTime = GetRunningTime()
- if event == "PROFILE_ACTIVATED" then
- ClearLog()
- POLL = Poll:new(POLL_FAMILY, POLL_DELAY)
- POLL:start()
- if KB_EVENTS then
- kb = EventHandler:new("kb")
- kb:ProcessEvent(event, arg, family)
- end
- if LHC_EVENTS then
- lhc = EventHandler:new("lhc")
- lhc:ProcessEvent(event, arg, family)
- end
- _onActivation(event, arg, family)
- else
- -- POLLING ROUTINES BELOW
- POLL:run(event,arg,family)
- if KB_EVENTS then kb:ProcessEvent(event, arg, family) end
- if LHC_EVENTS then lhc:ProcessEvent(event, arg, family) end
- _GetRunningTime = GetRunningTime()
- _OnEvent(event, arg, family) -- Runs myOnEvent to compartmentalize
- end
- if KB_EVENTS then kb:CleanupAfterEvent() end
- if LHC_EVENTS then lhc:CleanupAfterEvent() end
- end
- function log(...)
- if ... == nil then
- error("log(...) cannot display nil\n",2)
- end
- OutputLogMessage(...)
- end
- function Type(v)
- if type(v) == "table" then
- if v.Type ~= nil then
- return v.Type
- elseif v.type ~= nil then
- return v.type
- end
- end
- return type(v)
- end
- function typeString(s, delay)
- if s == nil then return end
- if not original then
- original = {}; originalShift = {}; baseKey = {}
- original[1] = { "`", "-", "=", "[", "]", "\\", ";", "'", ",", ".", "/", " " }
- originalShift[1] = { "~", "_", "+", "{", "}", "|", ":", '"', "<", ">", "?" }
- baseKey[1] = { "tilde", "minus", "equal", "lbracket", "rbracket", "backslash", "semicolon", "quote", "comma", "period", "slash", "spacebar" }
- original[2] = {}
- originalShift[2] = { "!", "@", "#", "$", "%", "^", "&", "*", "(", ")" }
- baseKey[2] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" }
- originalShift[3] = {}
- original[3] = { "\\", "\n", "\r", "\t", "\a", "\c", "\s" }
- baseKey[3] = { "backslash", "enter", "enter", "tab", "lalt", "lctrl", "lshift" }
- end
- for i=1, # s, 1 do
- local char = string.sub(s,i,i)
- local char2 = string.sub(s,i,i+1)
- if string.find(char,"%d") then -- if char is a digit
- PressAndReleaseKey(char)
- if delay then Sleep(delay) end
- elseif string.find(char,"%a") then -- if char is letter
- local lchar = string.lower(char)
- if char ~= lchar then
- PressKey("lshift")
- if delay then Sleep(delay) end
- end
- PressAndReleaseKey(lchar)
- if delay then Sleep(delay) end
- if char ~= lchar then ReleaseKey("lshift") end
- else -- if it's not a number or letter
- local match = false
- for index, value in ipairs(original) do
- for j, v in ipairs(original[index]) do -- check all enties in original
- if char == v or char2 == v then -- found a match
- PressAndReleaseKey( baseKey[index][j] ) -- press and release base key
- match = true -- flag that a match was found
- break
- end
- end
- if match then break end
- end
- if not match then -- if a match wasn't found, check for the originalShift values
- for index, value in ipairs(originalShift) do
- for j, v in ipairs(originalShift[index]) do -- check all enties in originalShift
- if char == v or char2 == v then -- found a match
- PressKey("lshift");
- if delay then Sleep(delay) end
- PressAndReleaseKey( baseKey[index][j] )
- ReleaseKey("lshift")
- match = true -- flag that a match was found
- break
- end
- end
- if match then break end
- end
- end
- if delay then Sleep(delay) end
- if not match then
- error("function typeString(s,delay) - '"..char.."' or '"..char2.."' not recognized.\n", 2)
- end
- end
- end
- end
- ------------------------------------------------------------------------------------------------------------
- -- function Poll:new(family, delay) delay is sleep time between polls
- -- function Poll:run(event, arg, family) handles events and performs the polling as long as it's running
- -- function Poll:setMKeyModifier( m1, m2, m3, family ) Allows the use of Modifiers to change M pages
- -- function Poll:start() turn on polling
- -- function Poll:stop() stop polling
- -- function Poll:_press() NOT TO BE USED
- -- function Poll:release() NOT TO BE USED
- -- function Poll:setMKeyState(MKeyState) NOT TO BE USED
- ------------------------------------------------------------------------------------------------------------
- Poll = {}
- Poll.__index = Poll
- Poll.__newindex = function(table, key, value)
- for k,v in pairs(table) do
- if k == key then
- rawset(table,key,value) return
- end
- end
- error("'" .. key .. "' is not a member of Poll.", 2)
- end
- function Poll:new(family, delay)
- local self = {}
- self.delay = delay or 50
- if family ~= "kb" and family ~= "lhc" then
- error("Poll:new() - 'pFamily' must be 'kb' or 'lhc'", 2)
- end
- self.pFamily = family
- self.presses = 0
- self.running = false
- self.runMKeyModifier = false
- self.MKeyModifier = { nil, nil, nil } -- "default" or Modifiers. i.e. "lshift", "ctrl"
- self.modFamily = ""
- self.Type = "Poll"
- setmetatable(self, Poll)
- return self
- end
- --------------------------------------------------------------------------------------------
- -- Poll:setMKeyModifier( m1, m2, m3, family )
- -- Sets what modifiers will change you to the associated M page of the device on family
- -- "shift", "ctrl", "alt", "lshift", "lctrl", "lalt"... are all modifiers
- -- "default" is the page that will be set when none of the listed modifiers are pressed
- -- "" will cause a page to be ignored.
- -- I.E. - Poll:setMKeyModifier( "default", "shift", "ctrl", "lhc" )
- -- will set the default page to m1, shift will change you to m2, ctrl to m3 on a left hand controler
- --------------------------------------------------------------------------------------------
- function Poll:setMKeyModifier( m1, m2, m3, family )
- self.runMKeyModifier = true
- self.MKeyModifier[1] = m1
- self.MKeyModifier[2] = m2
- self.MKeyModifier[3] = m3
- if family ~= "kb" and family ~= "lhc" then error("Poll:setMKeyModifier() family - needs to be 'kb' or 'lhc'",2) end
- self.modFamily = family
- end
- function Poll:start()
- self.running = true
- self:setMKeyState()
- end
- function Poll:stop()
- self.running = false
- end
- function Poll:_press()
- if self.running then
- self.presses = self.presses + 1
- end
- end
- function Poll:release()
- if self.running then
- self.presses = self.presses - 1
- end
- end
- function Poll:setMKeyState()
- if self.runMKeyModifier then
- local default = nil
- local i = 1
- local modMKeyState = nil
- for i = 1, 3, 1 do
- if self.MKeyModifier[i] == "default" then
- default = i
- elseif self.MKeyModifier[i] == "" then
- -- do nothing
- elseif string.find(self.MKeyModifier[i],"mb%d") then
- local iMB = tonumber(string.sub(self.MKeyModifier[i],3))
- if IsMouseButtonPressed(iMB) then
- modMKeyState = i
- end
- elseif IsModifierPressed(self.MKeyModifier[i]) then
- modMKeyState = i
- end
- end
- if modMKeyState == nil then
- modMKeyState = default
- end
- if modMKeyState ~= nil then
- if self.pFamily == self.modFamily then
- SetMKeyState(modMKeyState, self.pFamily)
- return
- elseif GetMKeyState(self.modFamily) ~= modMKeyState then
- SetMKeyState(modMKeyState, self.modFamily)
- end
- end
- end
- SetMKeyState( GetMKeyState(self.pFamily), self.pFamily )
- end
- function Poll:run(event, arg, family)
- if self.running and self.pFamily == family then
- if event == "M_PRESSED" then
- self:_press()
- elseif event == "M_RELEASED" then
- if self.presses == 1 then
- self:setMKeyState()
- Sleep(self.delay)
- end
- self:release()
- end
- end
- end
- --------------------------------------------------------------------------------------------------------
- -- function CoThread:new(f) f - function(coThread,...) coThread is the controlling CoThread
- -- function CoThread:recreate() kill existing coroutine and recreate
- -- function CoThread:create() creates coroutine
- -- function CoThread:isDead() true if coroutine is dead or nil/false
- -- function CoThread:run(...) run coroutine with variables don't include mt
- -- function CoThread:kill() kill coroutine
- -- function CoThread:yield() use in function(coThread,...) to yield
- -- function CoThread:sleep(Milliseconds) use in function(coThread,...) to sleep for Milliseconds
- -- function CoThread:start() does the same thing as recreate()
- -- function CoThread:stop() does the same thing as kill()
- -- function CoThread:isFinished() same as isDead()
- --------------------------------------------------------------------------------------------------------
- CoThread = {}
- CoThread.__index = CoThread
- function CoThread:new(f) -- f - function(MultiThread)
- local self = {}
- if type(f) ~= "function" then
- error("A function is needed",2)
- end
- self.func = f
- self.co = nil
- self.sleepUntilTimeStamp = nil
- self.Type = "CoThread"
- setmetatable(self, CoThread)
- return self
- end
- function CoThread:recreate()
- self:kill()
- self.co = coroutine.create(self.func)
- end
- function CoThread:create()
- self.co = coroutine.create(self.func)
- end
- function CoThread:isDead()
- if self.co == nil then
- return true
- elseif coroutine.status(self.co) == "dead" then
- self.co = nil
- return true
- else
- return false
- end
- end
- function CoThread:run(...)
- if self:isDead() then
- return
- end
- if self.sleepUntilTimeStamp ~= nil then
- if _GetRunningTime < self.sleepUntilTimeStamp then
- return
- else
- self.sleepUntilTimeStamp = nil
- end
- end
- coroutine.resume(self.co, self, ...)
- end
- function CoThread:kill()
- self.co = nil -- lua automatically deallocated
- self.sleepUntilTimeStamp = nil
- end
- function CoThread:yield()
- coroutine.yield()
- end
- function CoThread:sleep(Milliseconds)
- self.sleepUntilTimeStamp = _GetRunningTime + Milliseconds
- coroutine.yield()
- end
- function CoThread:start()
- self:recreate()
- end
- function CoThread:stop()
- self:kill()
- end
- function CoThread:isFinished()
- return self:isDead()
- end
- --------------------------------------------------------------------------------------------------------
- -- function EventHandler:new(family) Created an event handler for events of family ("lhc" or "kb")
- -- function EventHandler:ProcessEvent(event, arg, family) This will add events to the handler.
- -- function EventHandler:CleanUpEvent() This will clean up events that only happen once.
- -- To find out if an event or state is present, access it by EventHandler["name of event"]
- -- Events are of the following catagories: "g" - G key, "m" - M key, "mb" - mouse Button
- -- The event catagory is followed by a number for the button pressed (i.e. "G1", "M2", "B4")
- -- The event catagory and button number is followed by one of the following:
- -- _pressed, _released, _down, _toggle, _m = mkey state
- -- A completed event will look like g1m2_toggle or g3_down to signify that G1 is pressed on m2, or G3 is down
- -- under construction Modifiers are also available as "shift", "alt", "ctrl" and right and left alternatives "lshift" or "rshift"
- --------------------------------------------------------------------------------------------------------
- EventHandler = {}
- EventHandler.__index = EventHandler
- function EventHandler:new(family)
- local self = {}
- self.family = family
- self.Type = "EventHandler"
- setmetatable(self, EventHandler)
- return self
- end
- function EventHandler:ProcessEvent(event, arg, family)
- -- Create events for modifiers
- local modKeys = { "shift", "rshift", "lshift", "ctrl", "rctrl", "lctrl", "alt", "ralt", "lalt" }
- for k,v in pairs(modKeys) do
- if IsModifierPressed(v) then -- modifier is down
- if not self[v .. "_down"] then -- if just started being pressed, create pressed and down event
- self[v .. "_pressed"] = true
- self[v .. "_down"] = true
- if self[v .. "_toggle"] then
- self[v .. "_toggle"] = nil
- else
- self[v .. "_toggle"] = true
- end
- end
- else -- modifer is not down
- if self[v .. "_down"] then
- self[v .. "_down"] = nil
- self[v .. "_released"] = true
- end
- end
- end
- -- Create events for mouse buttons
- local mouseButtons = { "mb1", "mb2", "mb3", "mb4", "mb5" }
- for i,v in ipairs(mouseButtons) do
- if IsMouseButtonPressed(i) then -- Checks if mouse button is down. i = index, so mouseButtons must be in order from 1
- if not self[v .. "_down"] then -- if just started being pressed, create pressed and down event
- self[v .. "_pressed"] = true
- self[v .. "_down"] = true
- if self[v .. "_toggle"] then
- self[v .. "_toggle"] = nil
- else
- self[v .. "_toggle"] = true
- end
- end
- else -- mouseButton is not down
- if self[v .. "_down"] then
- self[v .. "_down"] = nil
- self[v .. "_released"] = true
- end
- end
- end
- -- Set MKeyState flag
- local curMState = GetMKeyState(self.family)
- local strMKeyState = "m" .. curMState
- self[strMKeyState .. "_m"] = true
- if family ~= self.family then
- return
- end
- -- remove MState events not on current MState
- for k, v in pairs(self) do
- local i, j = string.find(k, "m%d")
- if i ~= nil then
- if string.sub(k,i,j) ~= strMKeyState then
- if string.find(k,"g%dm%d_down") then -- create a released event for GKey releases on a different M page
- self[string.gsub(k,"_down","_released")] = true
- end
- if not string.find(k, "g%dm%d_toggle") then
- self[k] = nil
- end
- end
- end
- end
- local keyType = nil
- local keyNum = nil
- local eventType = {}
- -- create G and M events.
- if string.sub(event,1,1) == "G" or string.sub(event,1,1) == "M" then
- keyType = string.lower(string.sub(event,1,1))
- keyNum = arg
- if string.find(event, "PRESSED") then
- eventType = { "pressed", "down", "toggle" }
- elseif string.find(event, "RELEASED") then
- eventType = { "released" }
- else
- error("EventHandler:GetEventString(event, arg, family) - Not a recognized G or M event.\n",2)
- end
- for i,v in ipairs(eventType) do
- local keys = {}
- keys[1] = keyType .. tostring(arg) .. "_" .. v
- if keyType == "g" then
- keys[2] = keyType .. tostring(arg) .. strMKeyState .. "_" .. v
- end
- if v == "toggle" then
- for k,val in pairs(keys) do
- if self[val] then
- self[val] = nil
- else
- self[val] = true
- end
- end
- else
- for k, val in pairs(keys) do
- self[val] = true
- if v == "released" then -- if released, remove the _down event
- self[string.gsub(val, "released", "down")] = nil
- end
- end
- end
- end
- elseif string.find(event,"PROFILE") then
- eventType = string.sub(event,9)
- self[eventType] = true
- else
- error("EventHandler:GetEventString(event, arg, family) - Not a recognized event.\n",2)
- end
- end
- function EventHandler:CleanupAfterEvent()
- -- Clean up events like releases and presses to be removed now they've been used already
- for k, v in pairs(self) do
- if k == "ACTIVATED" or k == "DEACTIVATED" then
- self[k] = nil
- elseif string.find(k, "_pressed") then
- self[k] = nil
- elseif string.find(k, "_released") then
- self[string.gsub(k,"_released","_down")] = nil
- self[k] = nil
- end
- end
- end
- -- EOF
Advertisement
Add Comment
Please, Sign In to add comment