Brick_LuaLogic/bricks/inputs/keyboard-input.lua
2021-05-29 13:15:11 -05:00

25 lines
526 B
Lua

local function queueBit(gate, bit)
table.insert(gate.queueBits, 1, bit)
end
return function(gate, argv)
if argv[1]=="\\:" then argv[1] = ";" end
local keycode = keyboard_keyToCode[argv[1]] or keyboard_keyToCode["invalid"]
local status = keyboard_strToBool[argv[2]]
local code = keycode+(status and 128 or 0)
queueBit(gate, 1)
for bitidx = 1, 8 do
local val = bit.band(code, 0x80)
queueBit(gate, val)
code = bit.lshift(code, 1)
end
queueBit(gate, 0)
Gate.queue(gate, 0)
end