Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local monitor = peripheral.find("monitor")
- function writeToMonitor(x, y, txt, color)
- monitor.setTextColor(color)
- monitor.setCursorPos(x, y)
- monitor.write(txt)
- end
- -- Table of keys.
- keyMapping = {
- -- Maps (x * 100 + y) to the key.
- [308] = "1", [408] = "2", [508] = "3", [608] = "4", [708] = "5", [808] = "6", [908] = "7", [1008] = "8", [1108] = "9", [1208] = "0", [1308] = "'", [1608] = "bk",
- [309] = "Q", [409] = "W", [509] = "E", [609] = "R", [709] = "T", [809] = "Y", [909] = "U", [1009] = "I", [1109] = "O", [1209] = "P",
- [310] = "A", [410] = "S", [510] = "D", [610] = "F", [710] = "G", [810] = "H", [910] = "J", [1010] = "K", [1110] = "L",
- [311] = "Z", [411] = "X", [511] = "C", [611] = "V", [711] = "B", [811] = "N", [911] = "M", [1011] = ":", [1511] = " "
- }
- keyChars = {
- [308] = "1", [408] = "2", [508] = "3", [608] = "4", [708] = "5", [808] = "6", [908] = "7", [1008] = "8", [1108] = "9", [1208] = "0", [1308] = "'", [1608] = "<",
- [309] = "Q", [409] = "W", [509] = "E", [609] = "R", [709] = "T", [809] = "Y", [909] = "U", [1009] = "I", [1109] = "O", [1209] = "P",
- [310] = "A", [410] = "S", [510] = "D", [610] = "F", [710] = "G", [810] = "H", [910] = "J", [1010] = "K", [1110] = "L",
- [311] = "Z", [411] = "X", [511] = "C", [611] = "V", [711] = "B", [811] = "N", [911] = "M", [1011] = ":", [1511] = " "
- }
- --
- -- Data.
- screen = "startMenu"
- textInput = ""
- lastKeyX = 0
- lastKeyY = 0
- lastKeyText = " "
- --
- while screen ~= "exit" do
- monitor.clear()
- if screen == "startMenu" then
- writeToMonitor(1, 1, "[ Welcome to the ]", colors.yellow)
- writeToMonitor(1, 2, "[ Smart Storage! ]", colors.yellow)
- writeToMonitor(1, 5, "[_Store_All______]", colors.green)
- writeToMonitor(1, 7, "[_Turn_Off_______]", colors.red)
- local event, side, cx, cy = os.pullEvent("monitor_touch")
- -- print("The monitor on side " .. side .. " was touched at (" .. x .. ", " .. y .. ")")
- if cy == 7 then
- monitor.clear()
- screen = "exit"
- elseif cy == 5 then
- screen = "storeAll"
- end
- elseif screen == "storeAll" then
- local chest = peripheral.find("minecraft:chest")
- writeToMonitor(1, 1, "[Input Contents: ]", colors.yellow)
- for slot, item in pairs(chest.list()) do
- print(("%d x %s in slot %d"):format(item.count, item.name, slot))
- end
- local event, side, cx, cy = os.pullEvent("monitor_touch")
- elseif screen == "testKeyboard" then
- writeToMonitor(1, 2, textInput .. "|", colors.cyan)
- writeToMonitor(1, 7, "__________________", colors.white)
- writeToMonitor(1, 8, "| 1234567890' [<]|", colors.white)
- writeToMonitor(1, 9, "| QWERTYUIOP | |", colors.white)
- writeToMonitor(1, 10, "| ASDFGHJKL -' |", colors.white)
- writeToMonitor(1, 11, "| ZXCVBNM: [ ] |", colors.white)
- if lastKeyX ~= 0 then
- monitor.setCursorPos(lastKeyX, lastKeyY)
- monitor.blit(lastKeyText, "0", "d")
- end
- local event, side, cx, cy = os.pullEvent("monitor_touch")
- cxy = cx * 100 + cy
- if keyMapping[cxy] then
- local k = keyMapping[cxy]
- if k == "bk" then
- -- Delete last character.
- textInput = textInput:sub(1, -2)
- else
- textInput = textInput .. k
- end
- lastKeyText = keyChars[cxy]
- lastKeyX = cx
- lastKeyY = cy
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment