Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- MindenCucc QWERTZ keyboard API!
- -- For CC 1.51+ MC 1.5+
- -- Version 0.07
- -- Declare
- btns={}
- selectedINDEX=nil
- selectedInput="term"
- keyboardInput=""
- -- asd Button CLick (BCL) API
- -- REALLY HUGE table with fancy crap :D (smallest adv. button API xD)
- button={
- createINDEX=(
- function(INDEX)
- if btns[INDEX]==nil then
- btns[INDEX]={}
- end
- end),
- deleteINDEX=(
- function(INDEX)
- if btns[INDEX] ~= nil then -- If exist, delete it
- btns[INDEX]=nil
- end
- end),
- createButton=(
- function(INDEX, Ax1, Ax2, Ay1, Ay2, txt, Afunc, Aargs, Atoggle, AtxtColor, Acolor, Aret)
- btns[INDEX][txt]={}
- btns[INDEX][txt].x1=Ax1
- btns[INDEX][txt].x2=Ax2
- btns[INDEX][txt].y1=Ay1
- btns[INDEX][txt].y2=Ay2
- btns[INDEX][txt].debug=txt
- btns[INDEX][txt].args=Aargs
- if AtxtColor ~= nil then
- btns[INDEX][txt].txtColor = AtxtColor
- else
- btns[INDEX][txt].txtColor = colors.white
- end
- btns[INDEX][txt].func=Afunc --Implemented! YAAY! ^^ use funcName, {arg1, arg2...} :D
- if Atoggle then
- btns[INDEX][txt].ret=Aret or false -- Return state, ignored if toggle is false or nil CURRENTLY UNUSED!
- btns[INDEX][txt].color=colors.red
- btns[INDEX][txt].state=false
- else
- btns[INDEX][txt].ret=false
- btns[INDEX][txt].color=Acolor or colors.gray
- end
- btns[INDEX][txt].tglable=Atoggle or false -- Switch or button?
- end),
- deleteButton=(
- function(INDEX, txt)
- if btns[INDEX][txt] ~= nil then -- If exist, delete it
- btns[INDEX][txt]=nil
- return true
- else
- return false
- end
- end),
- drawButtons=(
- function(INDEX, bgColor, heading, headingColor)
- if bgColor == nil then
- bgColor = colors.cyan -- Color-Ma-TIC asdboard:65: attempt to perform arithmetic __sub on nil and nil :D
- end
- if heading == nil then
- heading = ""
- end
- termX, termY = term.getSize()
- for asdX = 1, termX do
- for asdY = 1, termY do
- term.setBackgroundColor(bgColor)
- term.setCursorPos(asdX, asdY)
- term.write(" ")
- end
- end
- if headingColor == nil then
- headingColor = colors.white
- end
- term.setTextColor(headingColor)
- term.setCursorPos(termX/2 - string.len(heading)/2, 1)
- term.write(heading)
- for btn, data in pairs(btns[INDEX]) do
- for px=btns[INDEX][btn].x1, btns[INDEX][btn].x2 do
- for py=btns[INDEX][btn].y1, btns[INDEX][btn].y2 do -- fancy_crap() end
- term.setBackgroundColor(btns[INDEX][btn].color)
- term.setCursorPos(px,py)
- term.write(" ")
- end
- end
- term.setTextColor(btns[INDEX][btn].txtColor)
- term.setCursorPos(math.floor(((btns[INDEX][btn].x1+btns[INDEX][btn].x2)/2) - (string.len(btns[INDEX][btn].debug)/2))+1, math.floor(btns[INDEX][btn].y1+btns[INDEX][btn].y2)/2) -- FANCY CRAP!
- term.write(btns[INDEX][btn].debug)
- end
- term.setTextColor(headingColor)
- end),
- setState=(
- function(INDEX, txt, value)
- btns[INDEX][txt].state=value
- end),
- doButton=(
- function(INDEX, mousex, mousey)
- for btn, btnData in pairs(btns[INDEX]) do
- if mousex >= btns[INDEX][btn].x1 and mousex <= btns[INDEX][btn].x2 then
- if mousey >= btns[INDEX][btn].y1 and mousey <= btns[INDEX][btn].y2 then
- if btns[INDEX][btn].state == true then
- btns[INDEX][btn].state=false
- btns[INDEX][btn].color=colors.red
- elseif btns[INDEX][btn].state == false then
- btns[INDEX][btn].state=true
- btns[INDEX][btn].color=colors.lime
- end -- FIXED! YAAY!
- if btns[INDEX][btn].args == nil then
- btns[INDEX][btn].func()
- else
- btns[INDEX][btn].func(btns[INDEX][btn].args) --Implemented! :D but buggy :(
- end
- end
- end
- end
- end),
- cleanUp=( -- WARNING! TOO FANCY!
- function(confirm)
- if confirm then
- btns=nil
- button=nil
- os.unloadAPI("asdboard")
- else
- error("DAFUQ ARE YOU PLAYING WITH THIS???", 2)
- end
- end)
- }
- -- END BCL
- -- MAIN FUNCTIONS
- function setUp()
- button.createINDEX("startup")
- button.createButton("startup", 3, 15, 3, 5, "Start", selectGUI, nil, false, colors.gray, colors.cyan, false)
- button.createButton("startup", 3, 15, 7, 9, "Manual select", selectManual_func, nil, true, colors.gray, nil, false)
- button.createButton("startup", 3, 15, 11, 13, "List inputs", listInputGUI, nil, false, colors.gray, colors.cyan, false)
- button.createButton("startup", 3, 15, 17, 19, "Cancel", exitProgram, nil, false, colors.gray, colors.purple, false)
- button.createINDEX("keyboard")
- end
- function selectedPeripheral(asd)
- selectedInput=asd
- end
- function listInputGUI()
- button.createINDEX("inputgui")
- local mon=listInputs()
- for i=1,#mon do
- button.createButton("inputgui", 3, 15, i+3, i+3, mon[i], selectedPheripheral, mon[i], false, colors.gray, colors.cyan, false)
- end
- button.createButton("inputgui", 3, 15, #mon+4, #mon+4, "term", selectedPerpiheral, "term", false, colors.black, colors.yellow, false)
- button.drawButtons("inputgui", colors.gray, "Select input device", colors.white)
- local event, asd1, asd2, asd3 = os.pullEvent()
- if event == "monitor_touch" and selectedInput == asd1 then
- button.doButton(selectedINDEX, asd2, asd3)
- elseif event == "mouse_click" then
- button.doButton(selectedINDEX, asd2, asd3)
- else
- write("CRASH!")
- sleep(.5)
- end
- sleep(.1)
- end
- function getTypes(sType)
- local fancyCrap = {}
- local net = {}
- local ret = {}
- if sType == nil or type(sType) ~= "string" then
- error("Cannot parse input.", 1)
- else
- net = peripheral.getNames()
- for asdX, valX in ipairs(net) do
- for netX = 1, #net do
- if peripheral.getType(valX) == sType then
- retval=true
- else
- retval=false
- end
- end
- if retval then
- table.insert(ret, valX)
- end
- end
- return ret
- end
- end
- function listInputs()
- local monitors = getTypes("monitor")
- return monitors
- end
- function exitProgram()
- startupRunning=false
- term.restore()
- end
- function returnText()
- editing=false
- return keyboardInput
- end
- function selectManual_func()
- manualSelect=true
- button.setState("startup", "Manual select", true)
- button.drawButtons("startup", colors.gray, "ASD-Board", colors.white)
- term.setCursorPos(3, 10)
- term.write("Click on that screen that you wanna use.")
- term.setBackgroundColor(colors.gray)
- local event, asd1, asd2, asd3 = os.pullEvent()
- if event == "monitor_touch" or event == "mouse_click" and manualSelect == true then
- if asd1 == 1 or asd1 == 2 or asd1 == 3 then
- selectedInput = term
- asdD=term
- else
- selectedInput = asd1
- asdD=peripheral.wrap(asd1)
- end
- asd1X, asd1Y=asdD.getSize()
- for xX=1,asd1X do
- for xY=1, asd1Y do
- asdD.setBackgroundColor(colors.gray)
- asdD.setCursorPos(xX, xY)
- asdD.write(" ")
- end
- end
- asdD.setCursorPos(2,3)
- asdD.write("Input selected :D")
- manualSelect = false
- else
- write("CRASH!")
- sleep(.5)
- end
- sleep(.1)
- end
- function input(txt)
- keyboardInput=keyboardInput..txt
- if selectedInput ~= "term" then
- sasd=peripheral.wrap(selectedInput)
- else
- sasd=term
- end
- sasd.setCursorPos(10,3)
- sasd.write(keyboardInput)
- end
- function redrawKeyboard()
- button.drawButtons(selectedINDEX, colors.black, "INPUT KEYBOARD", colors.white)
- term.setCursorPos(10,3)
- term.setTextColor(colors.white)
- term.write(keyboardInput)
- end
- function redrawText()
- term.setCursorPos(10,3)
- term.setTextColor(colors.white)
- term.write(keyboardInput)
- end
- function runKeyBoardLOOP()
- while editing do
- evt, asd1, asd2, asd3 = os.pullEvent()
- if evt == "monitor_touch" and selectedInput == asd1 then
- sleep(.1)
- button.doButton(selectedINDEX, asd2, asd3)
- redrawText()
- elseif evt == "mouse_click" and selectedInput == "term" then
- sleep(.1)
- button.doButton(selectedINDEX, asd2, asd3)
- redrawText()
- elseif evt == "char" then
- input(asd1)
- else
- peripheral.call(selectedInput, "write", "CRASH")
- sleep(.5)
- redrawKeyboard()
- end
- end
- end
- function void()
- write("")
- end
- function switchCase(as)
- selectedINDEX=as
- redrawKeyboard()
- end
- function runKeyBoard()
- button.createINDEX("keyboard")
- button.createINDEX("keyboard_shifted")
- button.createButton("keyboard", 2, 4, 5, 7, "1", input, "1", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 6, 8, 5, 7, "2", input, "2", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 10, 12, 5, 7, "3", input, "3", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 14, 16, 5, 7, "4", input, "4", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 18, 20, 5, 7, "5", input, "5", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 22, 24, 5, 7, "6", input, "6", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 26, 28, 5, 7, "7", input, "7", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 30, 32, 5, 7, "8", input, "8", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 34, 36, 5, 7, "9", input, "9", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 38, 40, 5, 7, "0", input, "0", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 42, 44, 5, 7, "-", input, "-", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 46, 48, 5, 7, "=", input, "=", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 2, 4, 9, 11, "q", input, "q", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 6, 8, 9, 11, "w", input, "w", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 10, 12, 9, 11, "e", input, "e", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 14, 16, 9, 11, "r", input, "r", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 18, 20, 9, 11, "t", input, "t", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 22, 24, 9, 11, "y", input, "y", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 26, 28, 9, 11, "u", input, "u", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 30, 32, 9, 11, "i", input, "i", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 34, 36, 9, 11, "o", input, "o", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 38, 40, 9, 11, "p", input, "p", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 42, 44, 9, 11, "[", input, "[", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 46, 48, 9, 11, "]", input, "]", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 2, 4, 13, 15, "a", input, "a", false, colors.gray, colors.white, false)
- button.createButton("keyboard", 6, 8, 13, 15, "s", input, "s", false, colors.gray, colors.white, false)
- button.createButton("keyboard", 10, 12, 13, 15, "d", input, "d", false, colors.gray, colors.white, false)
- button.createButton("keyboard", 14, 16, 13, 15, "f", input, "f", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 18, 20, 13, 15, "g", input, "g", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 22, 24, 13, 15, "h", input, "h", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 26, 28, 13, 15, "j", input, "j", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 30, 32, 13, 15, "k", input, "k", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 34, 36, 13, 15, "l", input, "l", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 38, 40, 13, 15, ";", input, ";", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 42, 44, 13, 15, "'", input, "'", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 46, 48, 13, 15, "\\", input, "\\", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 2, 4, 17, 19, "z", input, "z", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 6, 8, 17, 19, "x", input, "x", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 10, 12, 17, 19, "c", input, "c", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 14, 16, 17, 19, "v", input, "v", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 18, 20, 17, 19, "b", input, "b", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 22, 24, 17, 19, "n", input, "n", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 26, 28, 17, 19, "m", input, "m", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 30, 32, 17, 19, ",", input, ",", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 34, 36, 17, 19, ".", input, ".", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 38, 40, 17, 19, "/", input, "/", false, colors.white, colors.gray, false)
- button.createButton("keyboard", 2, 9, 2, 4, "RETURN", returnText, nil, false, colors.gray, colors.white, false)
- button.createButton("keyboard", 42, 44, 17, 19, "SPC", input, " ", false, colors.gray, colors.white, false)
- button.createButton("keyboard", 46, 48, 17, 19, "^", switchCase, "keyboard_shifted", false, colors.gray, colors.white, false)
- button.createButton("keyboard_shifted", 2, 4, 5, 7, "!", input, "!", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 6, 8, 5, 7, "@", input, "@", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 10, 12, 5, 7, "#", input, "#", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 14, 16, 5, 7, "$", input, "$", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 18, 20, 5, 7, "%", input, "%", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 22, 24, 5, 7, " ^ ", input, "^", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 26, 28, 5, 7, "&", input, "&", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 30, 32, 5, 7, "*", input, "*", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 34, 36, 5, 7, "(", input, "(", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 38, 40, 5, 7, ")", input, ")", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 42, 44, 5, 7, "_", input, "_", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 46, 48, 5, 7, "+", input, "+", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 2, 4, 9, 11, "Q", input, "Q", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 6, 8, 9, 11, "W", input, "w", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 10, 12, 9, 11, "E", input, "E", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 14, 16, 9, 11, "R", input, "R", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 18, 20, 9, 11, "T", input, "T", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 22, 24, 9, 11, "Y", input, "Y", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 26, 28, 9, 11, "U", input, "U", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 30, 32, 9, 11, "I", input, "I", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 34, 36, 9, 11, "O", input, "O", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 38, 40, 9, 11, "P", input, "P", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 42, 44, 9, 11, "{", input, "{", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 46, 48, 9, 11, "}", input, "}", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 2, 4, 13, 15, "A", input, "A", false, colors.gray, colors.white, false)
- button.createButton("keyboard_shifted", 6, 8, 13, 15, "S", input, "S", false, colors.gray, colors.white, false)
- button.createButton("keyboard_shifted", 10, 12, 13, 15, "D", input, "D", false, colors.gray, colors.white, false)
- button.createButton("keyboard_shifted", 14, 16, 13, 15, "F", input, "F", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 18, 20, 13, 15, "G", input, "G", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 22, 24, 13, 15, "H", input, "H", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 26, 28, 13, 15, "J", input, "J", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 30, 32, 13, 15, "K", input, "K", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 34, 36, 13, 15, "L", input, "L", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 38, 40, 13, 15, ":", input, ":", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 42, 44, 13, 15, "\"", input, "\"", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 46, 48, 13, 15, "|", input, "|", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 2, 4, 17, 19, "Z", input, "Z", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 6, 8, 17, 19, "X", input, "X", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 10, 12, 17, 19, "C", input, "C", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 14, 16, 17, 19, "V", input, "V", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 18, 20, 17, 19, "B", input, "B", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 22, 24, 17, 19, "N", input, "N", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 26, 28, 17, 19, "M", input, "M", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 30, 32, 17, 19, "<", input, "<", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 34, 36, 17, 19, ">", input, ">", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 38, 40, 17, 19, "?", input, "?", false, colors.white, colors.gray, false)
- button.createButton("keyboard_shifted", 2, 9, 2, 4, "RETURN", returnText, nil, false, colors.gray, colors.white, false)
- button.createButton("keyboard_shifted", 42, 44, 17, 19, "SPC", input, " ", false, colors.gray, colors.white, false)
- button.createButton("keyboard_shifted", 46, 48, 17, 19, "^", switchCase, "keyboard", false, colors.gray, colors.lightGray, false)
- editing=true
- selectedINDEX="keyboard"
- if selectedInput ~= "term" then
- local asd=peripheral.wrap(selectedInput)
- term.redirect(asd)
- redrawKeyboard()
- runKeyBoardLOOP()
- else
- redrawKeyboard()
- runKeyBoardLOOP()
- end
- end
- function startupGUI()
- while startupRunning do
- term.clear()
- selectedINDEX="startup"
- button.drawButtons(selectedINDEX, colors.gray, "ASD-Board", colors.white)
- term.setCursorPos(3,10)
- term.setTextColor(colors.white)
- term.write("Selected input: "..selectedInput)
- local event, asd1, asd2, asd3 = os.pullEvent()
- term.setCursorPos(1,2)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.gray)
- write(event) if asd1 ~= nil then write(", ") write(asd1) end if asd2 ~= nil then write(", ") write(asd2) end if asd3 ~=nil then write(", ") write(asd3) end
- if event == "mouse_click" or event == "monitor_touch" and manualSelect == false then
- button.doButton(selectedINDEX, asd2, asd3)
- else
- write("CRASH!")
- sleep(.5)
- end
- sleep(.1)
- end
- end
- function selectGUI(chr)
- startupRunning=false
- selectRunning=true
- if selectedInput ~= nil then
- ret=runKeyBoard(chr)
- return ret
- else
- while selectRunning do
- term.clear()
- listInputGUI()
- selectedINDEX="inputgui"
- local event asd1, asd2, asd3 = os.pullEvent()
- if event == "monitor_touch" and selectedInput == asd1 then
- button.doButton(selectedINDEX, asd2, asd3)
- elseif event == "monitor_touch" or event == "mouse_click" and manualSelect == true then
- selectedInput = asd1
- manualSelect = false
- elseif event == "mouse_click" then
- button.doButton(selectedINDEX, asd2, asd3)
- else
- write("CRASH")
- sleep(.5)
- end
- sleep(.1)
- end
- end
- end
- -- TEST/DEBUG LINES :D
- --[[
- function asd()
- button.createINDEX(1)
- button.createButton(1,3,13,5,9,"ASD", print("ASD!"), false, colors.cyan, colors.gray, false)
- button.createButton(1,3,13,10,14,"SUUUT", print("SUUUUUUTTT!!!"), true, colors.green, nil, false)
- button.drawButtons(1, nil, "ASD", nil)
- end
- function printButtonConfig(INDEX)
- local dataValue={}
- for btn, data in pairs(btns[INDEX]) do
- dataValue=data
- print(" "..btn)
- for int, val in pairs(dataValue) do
- write(" -- "..int..", ")
- print(val)
- end
- end
- end
- ]]--
- -- EOF TEST/DEBUG LINES :(
- -- STARTUP
- function readInput(chr)
- keyboardInput=""
- setUp()
- startupRunning=true
- startupGUI()
- input=returnText()
- return input
- end
Advertisement
Add Comment
Please, Sign In to add comment