Skip to content

Instantly share code, notes, and snippets.

@fischgeek
Created October 1, 2018 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fischgeek/9bce8bb4dec5556c451394539420d23b to your computer and use it in GitHub Desktop.
Save fischgeek/9bce8bb4dec5556c451394539420d23b to your computer and use it in GitHub Desktop.
function sendCommand(direction)
print("in sendcommand")
if lastKeys~="" then
print("hit it: " .. lastKeys)
file = io.open("c:\\dev\\logs\\lua.txt", "w")
file:write(lastKeys)
file:close()
lastKey=""
lastKeys=""
ignoreUp=true
setbuildUp(false)
else
print("lastKeys~='")
end
end
function setbuildUp(val)
buildUp=val
Observe("buildUp",val)
end
function Observe(name,val)
print("%s becomes %s" % {name,val})
end
function Set(list)
local set = {}
for _, l in ipairs(list) do set[l] = true end
return set
end
function setignoreUp(val)
ignoreUp=val
--Observe("ignoreUp",val)
end
function didReturn(id)
-- print("Returned from ID " .. id)
end
function handleIt(button, direction, device)
-- print("Device %s, Button %s, ignoreUp %s" % {device , button , ignoreUp})
if device=="Joy" then
button=button+1
end
if skipKeys[button] then
didReturn(1)
return
end
if direction==0 then
dir="up"
if device=="Joy" then
if button==3 then
Joy3Down=false
elseif button==4 then
Joy4Down=false
end
end
if ignoreUp and not buildUp then
didReturn(2)
return nil
end
setignoreUp(true)
else
dir="down"
if device=="Joy" then
if button==2 then --joy 2 down: listen
didReturn(3)
return
elseif button==3 then
Joy3Down=true
didReturn(4)
return
elseif button==4 then
Joy4Down=true
didReturn(5)
return
end
end
setignoreUp(false)
end
if Joy3Down then
device="Lefty"
end
if Joy4Down then
device=device .. "_Virt"
end
if Joy3Down and Joy4Down then
device=device .. "_VirtBang"
end
--print("Joy3Down: %s, Joy4Down: %s, Joy3Down: %s, device: %s" % {Joy3Down,Joy4Down,Joy3Down,device})
if device=="Joy" then
thisKey="%s%s" % {device , button}
else
thisKey="%s(%s)" % {device , button}
end
if force or (dir=="down" and buildUp) then
if lastKey~=thisKey then
lastKey=thisKey
lastKeys=lastKeys .. " " .. thisKey
print("print last keys %s" % {lastKeys})
end
else
cleanThisKey=thisKey
cleanThisKey=cleanThisKey:gsub("%(","%%(")
cleanThisKey=cleanThisKey:gsub("%)","%%)")
z=string.find(lastKeys,cleanThisKey)
print("device: %s, dir: %s, buildUp: %s, button: %s" % {device,dir,buildUp,button})
if ( dir=="up") and not buildUp then
print("doin it")
sendCommand()
print("did it")
elseif lastKey~=thisKey and not z then
if lastKeys=="" then
print("last keys is empty")
else
print("%s does not contain %s" % {lastKeys,thisKey})
end
lastKey=thisKey
lastKeys=lastKeys .. " " .. thisKey
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment