diff --git a/src/lua/core/computer.lua b/src/lua/core/computer.lua index b1607dc..a6f8e73 100644 --- a/src/lua/core/computer.lua +++ b/src/lua/core/computer.lua @@ -98,23 +98,23 @@ local asciitr = { } local escmap = { - A = 200, -- up - B = 208, -- down - C = 205, -- right - D = 203, -- left + [65] = 200, -- up + [66] = 208, -- down + [67] = 205, -- right + [68] = 203, -- left } -local inesc = 0 +local inesc_down = false function computer.signalTransformers.key_down(s, a, ascii, key, user) if key ~= -1 then return s, a, ascii, key, user end if ascii == 27 then - inesc = true + inesc_down = true return nil - elseif inesc then - if ascii < 48 and ascii > 57 and ascii ~= 59 and ascii ~= 91 then - inesc = false + elseif inesc_down then + if (ascii < 48 or ascii > 57) and ascii ~= 59 and ascii ~= 91 then + inesc_down = false key = escmap[ascii] or 0 ascii = 0 else @@ -124,16 +124,17 @@ function computer.signalTransformers.key_down(s, a, ascii, key, user) return s, a, math.floor(asciitr[ascii] or ascii), keymap[ascii] or key, user end +local inesc_up = false function computer.signalTransformers.key_up(s, a, ascii, key, user) if key ~= -1 then return s, a, ascii, key, user end if ascii == 27 then - inesc = true + inesc_up = true return nil - elseif inesc then - if ascii < 48 and ascii > 57 and ascii ~= 59 and ascii ~= 91 then - inesc = false + elseif inesc_up then + if (ascii < 48 or ascii > 57) and ascii ~= 59 and ascii ~= 91 then + inesc_up = false key = escmap[ascii] or 0 ascii = 0 else @@ -147,7 +148,7 @@ end function api.pushSignal(s, ...) local result = table.pack(computer.signalTransformers[s](s, ...)) - if result.n == 0 then return end + if result.n == 0 or not result[1] then return end result.n = nil signalQueue[#signalQueue + 1] = result end