Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- gL Project revision 2.0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --
- ClearLog(); gL={};gL.com={};gL.mode={};gL.SET={};gL.device={};gL.poll={};gL.KEY={} --
- -- G-Series Lua Script Template by UPIA ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --
- -- Toggle revision by Airwolf ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --
- -- SETUP ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- -- Keyboard Setup
- gL.device[0] = { "mml", 5, 6, 3 } -- regular keyboard and mouse (default: 5,6,3 / 0 = off)
- gL.device[1] = { "lhc", 29, 3 } -- G13: left-hand-controller = "lhc", 29 G-keys, 3 M-keys
- gL.device[2] = { "kb", 18, 3 } -- G15: keyoard = "kb", 18 G-keys, 3 M-keys
- -- Poll / Loop Setup
- gL.poll.autostart = 1 -- Start Poll with Script
- gL.poll.grid = 10 -- ( min Interval >= 10 ms )
- gL.poll.factor = 2 -- ( G-Key-Factor int >= 1 )
- gL.poll.steps = 0 -- ( 0 = off, 1 = 1 ms )
- -- Key Setup
- gL.KEY.fastclick = 200 -- Fast Click Time (for multi-click-selection)
- -- Play Mode Setup
- gL.com.PlayMode = "OnEvent" -- Play Mode ("OnEvent", "SET" or "Script")
- -- "SET" Mode Setup
- gL.KEY.showSET = 0 -- Log Assignment Slots
- -- "OnEvent" Mode Setup
- gL.com.OnEventDown = 1 -- Play "Down" Event
- -- /SETUP ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- -- Example for PlayMode "OnEvent" : (normal scripting, additional Keys (in poll): MB, MO, LO, additional event (in poll): _DOWN )
- gL.com.OnEvent = function(event, arg, family)
- family = family or "" -- family NOT nil
- --OutputLogMessage("event = %s, arg = %s, family = %s\n", event, arg, family) -- log events
- -- Profile Activation
- if event == "PROFILE_ACTIVATED" then OutputLogMessage("Profile activated in OnEvent Mode\n") end
- -- G-Keys (example)
- -- if event == "G_PRESSED" and arg == 1 then gL.poll.pause()
- -- Mouse Buttons
- if event == "MB_PRESSED" and arg == 4 then
- Mstate = not Mstate
- if Mstate then
- SetMKeyState(2,"lhc") -- if MB4 pressed => Set G13 to M2
- else
- SetMKeyState(1,"lhc") -- if MB4 pressed => Set G13 to M1
- end
- elseif event == "MB_PRESSED" and arg == 5 then
- Mstate = not Mstate
- if Mstate then
- SetMKeyState(3,"lhc") -- if MB5 pressed => Set G13 to M3
- else
- SetMKeyState(1,"lhc") -- if MB5 pressed => Set G13 to M1
- end
- end
- end
- -- Example for PlayMode "Script" : Using gL Key State Syntax gL.KEY.kb/lhc/mml.G/M/MB/MO/LO["name"].s=0/1/2/3=off/press/down/release
- gL.com.Script = function(pEvent)
- -- Profile Activation
- if pEvent == "PROFILE_ACTIVATED" then OutputLogMessage("Profile activated in Script Mode\n") end
- -- G1: Start / Stop Polling
- if gL.KEY.lhc.G[1].s == 1 then gL.poll.pause() end
- end
- -- Example for PlayMode "SET" : (Prototype) Play mode-defined key assignments gL.SET.kb/lhc/mml.M[0/1/2/3].MB[1].s[1/2/3]) M[0] => all M-Modes!
- gL.mode.default = function ()
- -- Profile Activation
- gL.SET.PA = function() OutputLogMessage("Profile activated in SET Mode\n") end
- -- G1: Start / Stop Polling
- gL.SET.lhc.M[0].G[1].s[1] = function() gL.poll.pause() end
- end
- -- More User Actions can simply be added to these special events:
- gL.com.gmEvents = function() -- play on every GM event
- -- user define
- end
- gL.com.pollEvents = function() -- play on every poll event
- -- user define
- end
- gL.com.gridEvents = function() -- play on every grid event
- -- user define
- end
- gL.com.stepEvents = function() -- play on every step event (ms)
- -- user define
- end
- gL.com.allkeysReleased = function() -- POLL ONLY! play, if all keys are released
- -- user define
- --OutputLogMessage("All Keys are released!\n")
- end
- function gL.KEY.defaultSetup() -- Define the Keys you want to use in gL
- -- ADD THE KEYS YOU WANT TO USE
- gL.KEY.setup.mml.MB = {1,2,3,4,5}
- gL.KEY.setup.mml.MO = {"lalt", "lctrl", "lshift", "ralt", "rctrl", "rshift"}
- gL.KEY.setup.mml.LO = {"capslock", "numlock", "scrolllock"}
- gL.KEY.setup.kb.G = {1,2,3,4,5,6,7,8,9,10,11,12}
- gL.KEY.setup.kb.M = {1,2,3}
- gL.KEY.setup.lhc.G = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29}
- gL.KEY.setup.lhc.M = {1,2,3}
- gL.com.setupkeys() -- setup the keys
- -- ADD THE DETAILED KEYS YOU WANT TO USE
- gL.KEY.setdetail( "mml", "MB", {1,2,3,4,5} )
- gL.KEY.setdetail( "mml", "MO", {"lalt", "lctrl", "lshift", "ralt", "rctrl", "rshift"} )
- gL.KEY.setdetail( "kb", "G", {1,2,3,4,5,6,7,8,9,10,11,12} )
- gL.KEY.setdetail( "kb", "M", {1,2,3} )
- gL.KEY.setdetail( "lhc", "G", {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29} )
- gL.KEY.setdetail( "lhc", "M", {1,2,3} )
- end
- -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- -- ~~ STOP EDITING HERE !!! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ gL Functions from here ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- -- Main Handler Functions ...
- function OnEvent(event,arg,family)
- gL.com.ini(event) -- initialize gL
- gL.com.setEvents(event,arg,family) -- set event values
- gL.com.setMmodes() -- set/update m-modes
- gL.com.filterPoll() -- set/filter Poll events
- --gL.com.showLog() -- print events to log
- gL.com.catchGM() -- catch GM events 1+3
- gL.com.catchP() -- catch PROFILE events
- gL.com.handler() -- play main handler (mml-events, step events ...)
- end
- gL.com.handler = function ()
- if gL.poll.on then -- Poll is on
- gL.poll.onLast = true
- if gL.com.E == "Poll" then
- local grid; local step
- gL.com.pollEvents() -- play Poll events
- --
- for grid = 1,gL.poll.factor,1 do
- -- Grid
- if gL.poll.on then gL.com.ComGridEvents() end -- play grid events (MM, rMacro, Mode.Grid, ...)
- if gL.poll.steps > 0 then
- for step = 1,gL.poll.grid/gL.poll.steps,1 do
- Sleep(gL.poll.steps)
- gL.com.time = gL.com.time + gL.poll.steps
- gL.com.ComStepEvents() -- play step events (e.g. millisecond macros)
- end
- Sleep(gL.poll.steps)
- gL.com.time = gL.com.time + gL.poll.steps
- else
- Sleep(gL.poll.grid)
- gL.com.time = gL.com.time + gL.poll.grid
- end
- end
- gL.com.SMKS(gL.com.M2, gL.com.family2)
- end
- end
- end
- gL.com.ComGridEvents = function() -- play assignments on grid events ----------------namechange!!!!!!!!!!
- -- Mouse&Modifiers, Record Macros ...
- gL.KEY.checkGM() -- Handle G,M Events in the loop (details, time ...)
- gL.KEY.catchMML() -- Handle MB,MO,LO Events
- gL.com.PlayEvents() -- Play all Events
- gL.com.gridEvents() -- Play user defined
- end
- gL.com.ComStepEvents = function() -- play assignments on step events (ms)
- gL.com.stepEvents() -- play user defined
- end
- -- Poll Handling ...
- gL.com.filterPoll = function() -- Analyze M action on Poll Device
- if table.getn(gL.device)==2 then
- if gL.poll.on and gL.com.F == gL.com.family2 and (gL.com.E == "M_PRESSED" or gL.com.E == "M_RELEASED") then
- gL.com.M2d = gL.com.A
- if gL.com.M2d == gL.com.M2 and gL.com.M2d == gL.com.M2l then -- Case 1: all the same
- if gL.com.E == "M_PRESSED" and gL.com.Er == "M_PRESSED" then -- Manual Press of the same M-Mode Button as M-Mode running
- gL.com.Er = gL.com.E; gL.com.Ep = "Poll0"; gL.com.Es = gL.com.E
- elseif gL.com.E == "M_RELEASED" and gL.com.Er == "M_RELEASED" then -- Manual Release same M-Mode
- gL.com.Er = gL.com.E; gL.com.Ep = "none"; gL.com.Es = gL.com.E
- else -- Regular Polling
- if gL.com.E == "M_PRESSED" then
- gL.com.Ep = "Poll0"; gL.com.Es = "Poll0"
- if gL.com.SMKS_set ~= 0 then -- SetMKeyState (same State press)
- gL.com.Ep = "none"; gL.com.Es = gL.com.E
- end
- else
- gL.com.Ep = "Poll"; gL.com.Es = "Poll"
- if gL.com.SMKS_set ~= 0 then -- SetMKeyState (same State release)
- gL.com.Ep = "none"; gL.com.Es = gL.com.E
- gL.com.SMKS_set = 0
- end
- end
- gL.com.Er = gL.com.E
- end
- elseif gL.com.M2d ~= gL.com.M2 and gL.com.M2 == gL.com.M2l then -- Case 2: Manual P/R on different M-Mode => Changing
- if gL.com.E == "M_PRESSED" then
- gL.com.Er = gL.com.E; gL.com.Ep = "none"; gL.com.Es = gL.com.E
- gL.com.PC = 1; gL.com.M2 = gL.com.A; gL.com.M[gL.com.family2]=gL.com.M2
- else gL.ERROR("unknown state 1") -- XXX
- end
- elseif gL.com.M2d ~= gL.com.M2 and gL.com.M2d == gL.com.M2l then -- Case 3: Delayed Poll (polling with old M-State) ADD M CHANGE for M.x??????????
- if gL.com.E == "M_PRESSED" then gL.com.Ep = "Poll0"; gL.com.Es = "Poll0" else gL.com.Ep = "Poll"; gL.com.Es = "Poll"; gL.com.PD = gL.com.PD + 1 end
- gL.com.Er = gL.com.E
- elseif gL.com.M2d == gL.com.M2 and gL.com.M2d ~= gL.com.M2l then -- Case 4:
- if gL.com.E == "M_RELEASED" and gL.com.Er == "M_RELEASED" then -- Manual different M-Mode Release
- gL.com.Er = gL.com.E; gL.com.Ep = "none"; gL.com.Es = gL.com.E
- gL.com.PC = 2
- elseif gL.com.E == "M_RELEASED" and gL.com.Es == "M_PRESSED" then -- Quick different Release / or SetMKeyState()
- gL.com.Er = gL.com.E; gL.com.Ep = "none"; gL.com.Es = gL.com.E
- gL.com.PC = 2
- else -- Waiting Poll (waiting for Release of M-Button)
- if gL.com.E == "M_PRESSED" then gL.com.Ep = "Poll0"; gL.com.Es = "Poll0" else gL.com.Ep = "Poll"; gL.com.Es = "Poll" end
- gL.com.Er = gL.com.E
- end
- else
- OutputLogMessage("ERROR: undef state 2\n\n")-- XXX
- end
- if gL.com.PC == 2 and gL.com.E == "M_RELEASED" then -- Check if Poll Change is complete and set M2l = M2s
- if gL.com.PD < 3 then -- wait 1 more poll (max. 2 delayed polls) .. make this variable (10ms => 3 polls, 25ms => 2polls)??
- gL.com.PD = gL.com.PD + 1
- elseif gL.com.PD >= 3 then -- PollChange complete
- gL.com.PC = 0; gL.com.PD = 0
- gL.com.M2l = gL.com.M2
- end
- end
- gL.com.E = gL.com.Es -- Change event !!!
- end
- elseif table.getn(gL.device) == 1 then -- Polling with fake device
- if gL.poll.on and gL.com.F == gL.com.family2 then
- if gL.com.E == "M_PRESSED" then gL.com.Es = "Poll0"
- elseif gL.com.E == "M_RELEASED" then gL.com.Es = "Poll"
- end
- gL.com.E = gL.com.Es -- Change event !!!
- end
- end
- -- Eliminate late Polls when Poll is off and reset PST and poll vars ..
- if gL.com.PST ~= 0 and gL.poll.on == false and gL.poll.onLast then
- if gL.com.F == gL.com.family2 and (gL.com.E == "M_PRESSED" or gL.com.E == "M_RELEASED") then
- if GetRunningTime() - gL.com.PST < (4 * gL.poll.factor * gL.poll.grid) then
- gL.com.E = "ignore"
- end
- end
- if GetRunningTime() - gL.com.PST > (4 * gL.poll.factor * gL.poll.grid) then -- add the reset on any event ?????????????????????
- gL.com.PST = 0; gL.poll.onLast = false
- end
- end
- end
- gL.poll.start = function ()
- gL.com.setTime()
- gL.poll.on = true
- gL.poll.onLast = true
- OutputLogMessage("--> Poll Start!!!\n")
- gL.com.SMKS(gL.com.M2d, gL.com.family2)
- end
- gL.poll.stop = function ()
- gL.com.PST = GetRunningTime()
- gL.poll.on = false
- gL.KEY.delActive()
- OutputLogMessage("--> Poll Stop!!!\n")
- end
- gL.poll.pause = function ()
- if gL.poll.on then gL.poll.stop() else gL.poll.start() end
- end
- -- Key Status Functions ...
- gL.com.catchP= function() -- Catch PROFILE events
- if gL.com.E == "PROFILE_ACTIVATED" or gL.com.E == "PROFILE_DEACTIVATED" then
- if gL.com.PlayMode == "OnEvent" then
- gL.com.OnEvent(gL.com.E,0) ---------------,"") ?????????????
- elseif gL.com.PlayMode == "SET" then
- local e
- if gL.com.E == "PROFILE_ACTIVATED" then e = "PA" elseif gL.com.E == "PROFILE_DEACTIVATED" then e = "PD" end
- if type(gL.SET[e]) == "function" then gL.SET[e]() end
- elseif gL.com.PlayMode == "Script" then
- gL.com.Script(gL.com.E)
- end
- end
- end
- function gL.KEY.checkGM() -- update G and M Keys on devices
- local device
- if gL.poll.on then
- for devices = 1,table.getn(gL.device),1 do
- device = gL.device[devices][1]
- for g,group in pairs({"G","M"}) do
- for n,name in pairs(gL.KEY.active[device][group]) do -- Update active keys -->
- if gL.KEY[device][group][name].s == 1 then -- if state is pressed, set to down
- gL.KEY[device][group][name].s = 2
- if gL.KEY[device][group][name].d == 1 then -- update details
- gL.KEY[device][group][name].tog = 0
- gL.KEY[device][group][name].time = gL.KEY[device][group][name].time + gL.poll.grid
- if gL.KEY[device][group][name].mcs ~= 0 then gL.KEY[device][group][name].mcs = 0 end -----------------?
- end
- elseif gL.KEY[device][group][name].s == 2 then -- if stae is on, update time
- if gL.KEY[device][group][name].d == 1 then gL.KEY[device][group][name].time = gL.KEY[device][group][name].time + gL.poll.grid end
- elseif gL.KEY[device][group][name].s == 3 then -- if state is released, set 0 and remove from active keys
- gL.KEY[device][group][name].s = 0
- if gL.KEY[device][group][name].d == 1 then gL.KEY[device][group][name].time = 0 end
- table.remove(gL.KEY.active[device][group],n) -- remove old releases
- elseif gL.KEY[device][group][name].s == -1 then -- PLAY PRESSES
- gL.KEY[device][group][name].s = 1
- if gL.KEY[device][group][name].d == 1 then
- gL.KEY[device][group][name].togstat = gL.KEY.toggle(gL.KEY[device][group][name].togstat)
- gL.KEY[device][group][name].tog = gL.KEY[device][group][name].togstat -- set toggle
- if ( gL.com.time - gL.KEY[device][group][name].last_r ) > gL.KEY.fastclick then
- gL.KEY[device][group][name].clicks = 0
- end -- sclick
- gL.KEY[device][group][name].last_p = gL.com.time
- end
- elseif gL.KEY[device][group][name].s == -3 then
- gL.KEY[device][group][name].s = 3
- if gL.KEY[device][group][name].d == 1 then
- if ( gL.com.time - gL.KEY[device][group][name].last_p ) <= gL.KEY.fastclick then -- shortclick detection
- gL.KEY[device][group][name].clicks = gL.KEY[device][group][name].clicks + 1
- --OutputLogMessage("clicks MB "..name.." : "..gL.KEY.mml[group][name].clicks.."\n")
- else
- gL.KEY[device][group][name].mcs = gL.KEY[device][group][name].clicks; gL.KEY[device][group][name].clicks=0
- end -- multiclick selection
- gL.KEY[device][group][name].last_r = gL.com.time
- end
- end
- end
- end
- end
- end
- end
- gL.com.catchGM = function() -- Catch G and M keys of the devices
- if gL.com.E == "M_PRESSED" or gL.com.E == "M_RELEASED" or gL.com.E == "G_PRESSED" or gL.com.E == "G_RELEASED" then -- GM event
- gL.com.gmEvents() -- play user defined
- local name, group, device, s
- name = gL.com.A
- device = gL.com.F
- if string.sub(gL.com.E,1,1) == "G" then group = "G" else group = "M" end
- if string.sub(gL.com.E,3,3) == "P" then -- PRESSED
- table.insert(gL.KEY.active[device][group],name)
- if gL.poll.on then
- s = -1
- gL.KEY[device][group][name].s = s
- else
- s = 1
- gL.KEY[device][group][name].s = s
- if gL.KEY[device][group][name].d == 1 then -- update details
- --
- gL.KEY[device][group][name].togstat = gL.KEY.toggle(gL.KEY[device][group][name].togstat)
- gL.KEY[device][group][name].tog = gL.KEY[device][group][name].togstat -- set toggle
- if ( gL.runtime() - gL.KEY[device][group][name].last_r ) > gL.KEY.fastclick then
- gL.KEY[device][group][name].clicks = 0
- end -- sclick
- gL.KEY[device][group][name].last_p = gL.runtime()
- end
- gL.com.PlayKey(device,group,name,s)
- end
- else -- RELEASED
- if gL.poll.on then
- if gL.KEY[device][group][name].s == -1 then -- check if key was pressed in the same grid, if so play press event
- gL.com.PlayKey(device,group,name,1)
- end
- s = -3
- gL.KEY[device][group][name].s = s
- else
- s = 3
- gL.KEY[device][group][name].s = s
- if gL.KEY[device][group][name].d == 1 then -- update details
- --
- if ( gL.runtime() - gL.KEY[device][group][name].last_p ) <= gL.KEY.fastclick then -- shortclick detection
- gL.KEY[device][group][name].clicks = gL.KEY[device][group][name].clicks + 1
- else
- gL.KEY[device][group][name].mcs = gL.KEY[device][group][name].clicks; gL.KEY[device][group][name].clicks=0
- end -- multiclick selection
- gL.KEY[device][group][name].last_r = gL.runtime()
- end
- gL.KEY[device][group][name].s = s
- gL.com.PlayKey(device,group,name,s) -- Play Key Release
- gL.KEY.removeActive(device,group,name) -- Remove from Active key-list
- s = 0 -- set state = 0
- gL.KEY[device][group][name].s = s
- end
- end
- end
- end
- function gL.KEY.catchMML() -- update Modifier and Mouse
- for g,group in pairs({"MB","MO"}) do
- for n,name in pairs(gL.KEY.active.mml[group]) do -- Update active keys -->
- if gL.KEY.mml[group][name].s == 1 then -- if state is pressed, set to down
- gL.KEY.mml[group][name].s = 2
- if gL.KEY.mml[group][name].d == 1 then -- update details
- gL.KEY.mml[group][name].tog = 0
- gL.KEY.mml[group][name].time = gL.KEY.mml[group][name].time + gL.poll.grid
- if gL.KEY.mml[group][name].mcs ~= 0 then gL.KEY.mml[group][name].mcs = 0 end -----------------?
- end
- elseif gL.KEY.mml[group][name].s == 2 then -- if stae is on, update time
- if gL.KEY.mml[group][name].d == 1 then gL.KEY.mml[group][name].time = gL.KEY.mml[group][name].time + gL.poll.grid end
- elseif gL.KEY.mml[group][name].s == 3 then -- if state is released, set 0 and remove from active keys
- gL.KEY.mml[group][name].s = 0
- gL.KEY.mml[group][name].time = 0
- table.remove(gL.KEY.active.mml[group],n) -- remove old releases
- end
- end
- end
- for v,i in pairs(gL.KEY.setup.mml.LO) do -- set old presses, releases to down/off
- if gL.KEY.mml.LO[i].s == 1 then -- change events 1 and 3
- gL.KEY.mml.LO[i].s = 2
- table.remove(gL.KEY.active.mml.LO,v)-- remove active
- elseif gL.KEY.mml.LO[i].s == 3 then
- gL.KEY.mml.LO[i].s = 0
- table.remove(gL.KEY.active.mml.LO,v)-- remove active
- end
- end
- for g,group in pairs({"MB","MO"}) do
- for n,name in pairs(gL.KEY.setup.mml[group]) do -- Mouse Buttons and modifiers
- if gL.KEY.check[group](name) then
- if gL.KEY.mml[group][name].s == 0 then -- pressed
- gL.KEY.mml[group][name].s = 1
- table.insert(gL.KEY.active.mml[group], name)
- if gL.KEY.mml[group][name].d == 1 then
- gL.KEY.mml[group][name].togstat = gL.KEY.toggle(gL.KEY.mml[group][name].togstat)
- gL.KEY.mml[group][name].tog = gL.KEY.mml[group][name].togstat -- set toggle
- if ( gL.com.time - gL.KEY.mml[group][name].last_r ) > gL.KEY.fastclick then
- gL.KEY.mml[group][name].clicks = 0
- end -- sclick
- gL.KEY.mml[group][name].last_p = gL.com.time
- end
- end
- else
- if gL.KEY.mml[group][name].s > 0 then -- released
- gL.KEY.mml[group][name].s = 3
- if gL.KEY.mml[group][name].d == 1 then
- if ( gL.com.time - gL.KEY.mml[group][name].last_p ) <= gL.KEY.fastclick then -- shortclick detection
- gL.KEY.mml[group][name].clicks = gL.KEY.mml[group][name].clicks + 1
- else
- gL.KEY.mml[group][name].mcs = gL.KEY.mml[group][name].clicks; gL.KEY.mml[group][name].clicks=0
- end -- multiclick selection
- gL.KEY.mml[group][name].last_r = gL.com.time
- end
- end
- end
- end
- end
- for v,i in pairs(gL.KEY.setup.mml.LO) do -- New Lock Keys
- if IsKeyLockOn(i) then
- if gL.KEY.mml.LO[i].s == 0 then
- gL.KEY.mml.LO[i].s = 1
- table.insert(gL.KEY.active.mml.LO, i) -- set active
- end
- else
- if gL.KEY.mml.LO[i].s == 1 or gL.KEY.mml.LO[i].s == 2 then
- gL.KEY.mml.LO[i].s = 3
- table.insert(gL.KEY.active.mml.LO, i) -- set active
- end
- end
- end
- end
- function gL.KEY.removeActive(device,group,name) -- remove special key from active
- local winner --= nil
- for i,n in ipairs(gL.KEY.active[device][group]) do
- if name == n then winner = i end
- end
- if winner ~= nil then table.remove(gL.KEY.active[device][group],winner) end
- end
- function gL.KEY.delActive() -- delete all active keys
- local device,group,name, i,g
- for i,devices in pairs(gL.device) do
- device = devices[1]
- for g = 1,table.getn(gL.KEY.defaults[device]),1 do
- group = gL.KEY.defaults[device][g]
- gL.KEY.active[device][group] = {}
- end
- end
- end
- function gL.KEY.emptyactive() -- initiate empty keys
- gL.KEY.active = {}
- for i,device in pairs(gL.device) do
- gL.KEY.active[device[1]] = {}
- if i == 0 then
- if device[2] > 0 then gL.KEY.active[device[1]].MB = {} end
- if device[3] > 0 then gL.KEY.active[device[1]].MO = {} end
- if device[4] > 0 then gL.KEY.active[device[1]].LO = {} end
- else
- if device[2] > 0 then gL.KEY.active[device[1]].G = {} end
- if device[3] > 0 then gL.KEY.active[device[1]].M = {} end
- end
- end
- end
- function gL.KEY.updateLO()
- for i,name in pairs(gL.KEY.setup.mml.LO) do
- --local name = gL.KEY.defaults.LO[i]
- if IsKeyLockOn(name) then
- gL.KEY.mml.LO[name].s = 2
- else
- gL.KEY.mml.LO[name].s = 0
- end
- end
- end
- function gL.KEY.toggle(stat)
- if stat == 1 then stat=2 else stat=1 end
- return stat
- end
- function gL.KEY.setdetail(device, group, array)
- local winner = ""
- for n1,name1 in pairs(gL.KEY.setup[device][group]) do
- for n2,name2 in pairs(array) do
- if name1 == name2 then winner = name1 end
- end
- if winner ~= "" then
- gL.KEY[device][group][winner] = {s=0, d=1, tog=0, togstat=2, clicks=0, mcs=0, time=0, last_p=0, last_r=0}
- else
- gL.KEY[device][group][winner] = {s=0, d=0, tog=0, togstat=2, clicks=0, mcs=0, time=0, last_p=0, last_r=0}
- end
- end
- end
- -- Com Functions ...
- gL.com.ini = function (event) -- Set initial values
- if event == "PROFILE_ACTIVATED" then
- OutputLogMessage("gL Project running ..\n---\n")
- -- Poll Vars
- gL.com.time = 0 -- ini: time is 0
- gL.poll.on = false -- ini: poll is off
- gL.poll.onLast = false -- ni: last poll status is off
- gL.poll.onNext = false
- -- Start-Parameter for "setpoll" with 2 devices present
- gL.com.Ep = "Poll" -- Event poll
- gL.com.Er = "M_RELEASED" -- Event real
- gL.com.Es = "Poll" -- Event set
- gL.com.PC = 0 -- Poll Change
- gL.com.PD = 0 -- Poll Delayed
- gL.com.PCM = 0 -- Poll Change Mode
- gL.com.PST = 0 -- Poll Stop Time
- gL.com.SMKS_set = 0 -- SetMKeyState detection
- -- Mstate Array
- gL.com.M = {} -- M["kb/lhc"]=1/2/3
- gL.com.AKR = 1
- -- Key Vars
- gL.KEY.setup = {}
- gL.KEY.setup.mml = {}
- gL.KEY.setup.kb = {}
- gL.KEY.setup.lhc = {}
- gL.KEY.defaults = {}
- gL.KEY.defaults.mml = {"MB","MO","LO"}
- gL.KEY.defaults.kb = {"G","M"}
- gL.KEY.defaults.lhc = {"G","M"}
- -- Key Check Functions
- gL.KEY.check = {}
- gL.KEY.check.MB = IsMouseButtonPressed
- gL.KEY.check.MO = IsModifierPressed
- gL.KEY.emptyactive()
- --gL.com.setupkeys() --moved to mode-------------------------------- !!! keys need to be setup in default mode!
- gL.KEY.defaultSetup()
- -- Load User Device Settings
- gL.com.setdevice()
- -- Set initial M-States
- if gL.com.M1 == nil then gL.com.M1 = GetMKeyState(gL.com.family1) end -- set M-Mode for main device
- if gL.com.M2d == nil then
- gL.com.M2d = GetMKeyState(gL.com.family2) -- set M-Mode for Poll device
- if gL.com.M2l == nil then gL.com.M2l = gL.com.M2d end -- set last M-Modes for Poll device
- if gL.com.M2 == nil then gL.com.M2 = gL.com.M2d end
- end
- gL.com.M["mml"]=gL.com.M1
- gL.com.M[gL.com.family1]=gL.com.M1
- gL.com.M[gL.com.family2]=gL.com.M2
- -- Load default mode settings
- if gL.com.PlayMode == "SET" then gL.mode.default() end
- -- Autostart Poll
- if gL.poll.autostart == 1 then gL.poll.start() end
- end
- -- ANY EVENT
- gL.com.runtime = nil -- reset runtime var
- --if gL.poll.on then gL.poll.onNext = true else gL.poll.onNext = false end -- set poll change varXXXXXXXXXXXXX
- end
- gL.com.setEvents = function(event,arg,family) -- Set Event Variables sent to OnEvent()
- gL.com.E = event
- gL.com.A = arg
- if family == "" then gL.com.F = "all" else gL.com.F = family end
- end
- gL.com.setMmodes = function() -- set/update M-Modes for devices
- if gL.com.E == "M_PRESSED" and gL.com.F == gL.com.family1 then -- update M-Mode for main device
- gL.com.M1 = gL.com.A
- elseif gL.poll.on == false and gL.com.E == "M_PRESSED" and gL.com.F == gL.com.family2 then -- update M-Mode for poll device if not polling
- gL.com.M2 = gL.com.A
- end
- gL.com.M[gL.com.family1] = gL.com.M1
- gL.com.M[gL.com.family2] = gL.com.M2
- gL.com.M["mml"]=gL.com.M1
- end
- function gL.com.setupkeys() -- create SET-assignment-array & KEY-status-array (for all keys set in gL.device)
- local device,group,name,detail,tab, d,m,g,n,s,x
- -- Profile Events
- gL.SET.PA = {}
- gL.SET.PD = {}
- -- Devices
- for d = 0, table.getn(gL.device),1 do
- device = gL.device[d][1]
- gL.SET[device]={}; gL.KEY[device] = {}
- -- M-Modes
- gL.SET[device].M = {}--; gL.KEY[device].M = {}
- for m = 0,3,1 do
- gL.SET[device].M[m] = {}--; gL.KEY[device].M[m] = {}
- for g = 1,table.getn(gL.KEY.defaults[device]),1 do
- -- Groups
- group = gL.KEY.defaults[device][g]
- gL.SET[device].M[m][group] = {}
- gL.KEY[device][group] = {}
- for i,name in pairs(gL.KEY.setup[device][group]) do
- -- Names
- gL.SET[device].M[m][group][name] = {}
- gL.SET[device].M[m][group][name].s = {}
- gL.KEY[device][group][name] = {s=0, d=1, tog=0, togstat=2, clicks=0, mcs=0, time=0, last_p=0, last_r=0}
- for s = 0,3,1 do
- -- States
- gL.SET[device].M[m][group][name].s[s] = 0 -- initial assignment = 0
- end
- end
- end
- end
- end
- gL.KEY.updateLO()
- end
- function gL.com.setdevice() -- set the main and polling device keyboards
- if table.getn(gL.device) == 2 then
- gL.com.family1 = gL.device[1][1]
- gL.com.family2 = gL.device[2][1]
- elseif table.getn(gL.device) == 1 then
- if gL.device[1][1] == "lhc" then
- gL.com.family1 = "lhc"
- gL.com.family2 = "kb"
- elseif gL.device[1][1] == "kb" then
- gL.com.family1 = "kb"
- gL.com.family2 = "lhc"
- else
- gL.ERROR("gL.com.setdevice => unknown keyboard family set!")
- end
- else
- gL.ERROR("gL.com.setdevice => illegal amount of keyboards set!") -- add no keyboard support
- end
- end
- gL.com.SMKS = SetMKeyState -- Hijack SetMKeyState to detect SMKS on same M-Mode
- SetMKeyState = function (state, device) -- Notify gL if SetMKeyState on Poll Device was pressed in same State!
- if gL.poll.on and device == gL.com.family2 and state == gL.com.M[gL.com.family2] then
- gL.com.SMKS_set = state
- end
- gL.com.SMKS(state,device)
- end
- gL.com.setTime = function ()
- gL.com.time = math.ceil( GetRunningTime() / gL.poll.grid ) * gL.poll.grid
- end
- gL.com.showLog = function () -- logging key action to OutputLog // outdated!!!!!!!!!!!
- if gL.com.Es ~= "Poll0" and gL.com.E ~= "Poll" and gL.com.E ~= "ignore" then
- OutputLogMessage(" [ "..gL.com.time.." "..GetRunningTime().."] \t\t\t "..gL.com.E.."\t"..gL.com.A.." "..gL.com.F.." \tM1:"..gL.com.M1.."\tM2:"..gL.com.M2.."\n")
- end
- end
- function gL.runtime()
- if gL.com.runtime == nil then gL.com.runtime = GetRunningTime() end
- return gL.com.runtime
- end
- function gL.com.PlayEvents() -- POLL ONLY! play all stacked events
- local device,group,name,winner, i,g
- winner = 0
- for i,devices in pairs(gL.device) do
- device = devices[1]
- for g = 1,table.getn(gL.KEY.defaults[device]),1 do
- group = gL.KEY.defaults[device][g]
- for i,name in pairs (gL.KEY.active[device][group]) do
- winner = winner + 1
- gL.com.PlayKey(device,group,name,gL.KEY[device][group][name].s)
- end
- end
- end
- if winner == 0 then
- if gL.com.AKR == 0 then
- gL.com.AKR = 1
- gL.com.allkeysReleased()
- end
- else
- if gL.com.AKR == 1 then gL.com.AKR = 0 end
- end
- end
- function gL.com.PlayKey(device, group, name, state) -- Play Mode for Keys ("SET", "OnEvent", User-Function)
- --OutputLogMessage("PlayKey: "..device.." "..group.." "..name.." "..state.." "..gL.KEY[device][group][name].s.."\n")
- if gL.com.PlayMode == "OnEvent" then gL.com.PlayOnEvent(device,group,name,state)
- elseif gL.com.PlayMode == "Script" then gL.com.PlayScript()
- elseif gL.com.PlayMode == "SET" then gL.com.PlaySET(device,group,name,state)
- else
- -- OPTIONAL: dev function ...
- end
- end
- function gL.com.PlayScript() -- Play SET Mode
- gL.com.Script()
- end
- function gL.com.PlaySET(device,group,name,state) -- Play SET Mode
- local MS; if device == "mml" then MS = gL.com.M1 else MS = gL.com.M[device] end -- set M-Modes
- if type(gL.SET[device].M[0][group][name].s[state]) == "function" then
- gL.SET[device].M[0][group][name].s[state]()
- if gL.KEY.showSET == 1 then OutputLogMessage("gL.SET[%s].M[0].%s[%s].s[%s]() playing!\n", device, group, name, state) end
- elseif type(gL.SET[device].M[MS][group][name].s[state]) == "function" then
- gL.SET[device].M[MS][group][name].s[state]()
- if gL.KEY.showSET == 1 then OutputLogMessage("gL.SET[%s].M[%s].%s[%s].s[%s]() playing!\n", device, MS, group, name, state) end
- else
- if gL.KEY.showSET == 1 then OutputLogMessage("gL.SET[%s].M[%s].%s[%s].s[%s]() not defined!\n", device, MS, group, name, state) end
- end
- end
- function gL.com.PlayOnEvent(device,group,name,state) -- Play OnEvent Mode
- local p = "_PRESSED"
- local r = "_RELEASED"
- local d = "_DOWN"
- if state == 1 then
- gL.com.OnEvent(group..p, name, device)
- elseif state == 2 and gL.com.OnEventDown == 1 then
- gL.com.OnEvent(group..d, name, device)
- elseif state == 3 then
- gL.com.OnEvent(group..r, name, device)
- end
- end
- --eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement