import std/[strutils, os, tables] var gfisnum = false gdisplaystr = "" gbinop = "+" gax = 0.0 gbx = 1.0 MAXDISP = 24 const kbd = [ ("Off", 2628095), ("C", 2628095), (" 0: if gdisplaystr.len == 1: displaystr("0", 6052991) gdisplaystr.setLen(gdisplaystr.len - 1) if gdisplaystr.len > 0: displaystr(gdisplaystr, 6052991) of 18: if gdisplaystr.len > 0: if gdisplaystr[0] == '-': gdisplaystr = gdisplaystr[1..^1] elif gdisplaystr.len < (MAXDISP - 1): gdisplaystr = "-" & gdisplaystr displaystr(gdisplaystr, 6052991) of 3, 7, 11, 15: gbinop = kbd[rowcol][0] try: gax = parseFloat(gdisplaystr) except: gax = 0.0 gfisnum = false of 19: if gfisnum: try: gbx = parseFloat(gdisplaystr) except: gbx = 0.0 gfisnum = false case gbinop of "+": gax = gax + gbx of "-": gax = gax - gbx of "*": gax = gax * gbx of "/": gax = if gbx != 0: gax / gbx else: 0.0 else: discard gdisplaystr = $gax displaystr(gdisplaystr, 6052991) else: discard let keyMap = {79:0, 111:0, 99:1, 67:1, 8:2, 42:3, 55:4, 56:5, 57:6, 47:7, 52:8, 53:9, 54:10, 43:11, 49:12, 50:13, 51:14, 45:15, 48:16, 46:17, 105:18, 73:18, 61:19}.toTable while true: let line = try: stdin.readLine() except EOFError: break if line == "drawapp": stdout.writeLine "Fo 0 611 3\nFo 1 400 3\nFo 2 140 3" stdout.writeLine "F 0 16777215\nFR 0 0 0 10000 10000\nB 0 12632256" for i in 0..= 3: let (btn, px, py) = (parseInt(parts[0]), parseInt(parts[1]), parseInt(parts[2])) if px >= 0: let row = (py - 1200) div 1200 let col = (px - 200) div 2000 if row in 0..4 and col in 0..3: keytoexe(row * 4 + col) elif px == -2: if keyMap.contains(btn): keytoexe(keyMap[btn]) elif px == -4: stdout.writeLine "Rz ", btn, " ", py elif px == -5: stdout.writeLine "Mv ", btn, " ", py elif px == -98: sleep(py) except: discard