Posted 09 April 2016 - 12:59 AM
                I have some code:
Why?
                
            
local c, x, y
local function tobinary(code)
  --From Online
  local rest, i
  local t ={}
  while code > 0 do
    rest = math.fmod(code, 2)
    table.insert(t, rest)
    code = (code - rest)/2
  end
  local x = table.concat(t)
  if string.len(x) <= 8 then
    for i = 0, 7 - string.len(x) do
	  x = '0'..x
    end
  else
    x=string.sub(x, #x - 8, #x)
  end
  return x
end
function getKeyboardInput()
  coroutine.yield()
  os.queueEvent('key')
  local tEveArgs = {coroutine.yield('key')}
  if tEveArgs[2] == 219 then
    printError('Windows 8 key not supported')
    tEveArgs[2] = 0
  end
  --print(type(tEveArgs[2]))
  if tEveArgs[2] == nil then
    tEveArgs[2] = 0
  end
  return tobinary(tEveArgs[2])
end
function getMouseInput()
  --This is very accurate, assuming the mouse stays in canvas.
  os.queueEvent('')
  local events = {coroutine.yield()}
  local noBin = '00000000'
  if c == nil or events[1] == 'mouse_up' then
    c = noBin
    x = noBin
    y = noBin
  elseif events[1] == 'mouse_click' or events[1] == 'mouse_drag' then
    if events[2] == 1 then
	  c = '00000001'
    else
	  c = '00000010'
    end
    x = tobinary(events[3])
    y = tobinary(events[4])
  end
  return c, x, y
end
while true do
  print(getKeyboardInput())
  for k,v in ipairs({getMouseInput()}) do
    print(v)
  end
end
Why?
 
         
                