-- Wireless Keyboard Receiver (Host Side) -- Find modem automatically local modemSide = nil for _, side in ipairs(redstone.getSides()) do if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then modemSide = side break end end if not modemSide then print("Error: No modem found!") return end rednet.open(modemSide) term.clear() term.setCursorPos(1, 1) print("=== Wireless Keyboard Receiver ===") print("Ready. Waiting for input...") print("---------------------------------") local inputBuffer = "" local currentLine = 4 local function refreshInput() term.setCursorPos(1, currentLine) term.clearLine() write("> " .. inputBuffer) end refreshInput() while true do local senderID, msg = rednet.receive() if type(msg) == "string" then if msg == "\b" then -- Handle backspace if #inputBuffer > 0 then inputBuffer = inputBuffer:sub(1, -2) end elseif msg == "\n" then -- Handle enter: run command term.setCursorPos(1, currentLine + 1) shell.run(inputBuffer) inputBuffer = "" currentLine = select(2, term.getCursorPos()) + 1 -- Auto scroll when reach bottom local _, screenH = term.getSize() if currentLine >= screenH then term.scroll(1) currentLine = screenH - 1 end else -- Add normal character inputBuffer = inputBuffer .. msg end refreshInput() end end