Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --attempt at a keyboard in lpp-3ds
- --using HBKBLib (by jbr373) keyboard images
- white = Color.new(255,255,255)
- function keyboard(question)
- state = 1
- oldstate = 0
- X, Y, line, column = 0, 0, 0, 0
- oldPos = -1
- offX = 32
- offY = 40
- text = ""
- states = { "abc_lower", "abc_upper", "special"}
- numbers = {"1","2","3","4","5","6","7","8","9","0"}
- line2_abc_lower = {"q","w","e","r","t","y","u","i","o","p"}
- line3_abc_lower = {"a","s","d","f","g","h","j","k","l"}
- line4_abc_lower = {"z","x","c","v","b","n","m"}
- line2_abc_upper = {"Q","W","E","R","T","Y","U","I","O","P"}
- line3_abc_upper = {"A","S","D","F","G","H","J","K","L"}
- line4_abc_upper = {"W","X","C","V","B","N","M"}
- line2_special = {"!",'"',"§","$","%","&","/", "(",")","?"}
- line3_special = {"*","'","<",">","+","[","]","{","}"}
- line4_special = {",",";",".",":","-","_","="}
- image = Screen.loadImage(System.currentDirectory().."/hbkb_abc_lower.png")
- Screen.debugPrint(5,5,question,white,TOP_SCREEN)
- while true do
- Screen.waitVblankStart()
- Screen.refresh()
- if oldstate ~= state then
- Screen.freeImage(image)
- oldstate = state
- image = Screen.loadImage(System.currentDirectory().."/hbkb_"..states[state]..".png")
- Screen.clear(BOTTOM_SCREEN)
- Screen.drawImage(0, 0, image, BOTTOM_SCREEN)
- end
- X, Y = Controls.readTouch()
- if X+Y > 0 then
- line = math.floor(Y/offY)+1
- column = math.floor(X/offX)+1
- else
- line = 0
- column = 0
- end
- if oldPos ~= line+column then
- oldPos = line+column
- if line == 1 then
- text = text..numbers[column]
- elseif line == 2 then
- cLine = _G["line2_"..states[state]]
- text = text..cLine[column]
- elseif line == 3 then
- if column == 10 then
- text = string.sub(text,1,-2)
- else
- cLine = _G["line3_"..states[state]]
- text = text..cLine[column]
- end
- elseif line == 4 then
- if column <= 2 then
- if state == 3 then state = 1 else state = 3 end
- elseif column == 10 then
- text = string.sub(text,1,-2)
- else
- cLine = _G["line4_"..states[state]]
- text = text..cLine[column-2]
- end
- elseif line == 5 then
- if column <= 2 then
- if state == 2 then state = 1 else state = 2 end
- caps = true
- elseif column >= 9 then
- if state == 2 then state = 1 else state = 2 end
- caps = false
- else
- text = text.." "
- end
- elseif line == 6 then
- if column > 5 then
- text = "validate"
- else
- text = "cancel"
- end
- end
- Screen.clear(TOP_SCREEN)
- Screen.debugPrint(5,5,question,white,TOP_SCREEN)
- Screen.debugPrint(5,20,text,white,TOP_SCREEN)
- end
- pad = Controls.read()
- if pad ~= oldPad then
- oldPad = pad
- if Controls.check(pad,KEY_START) then
- Screen.freeImage(image)
- System.exit()
- elseif Controls.check(pad, KEY_B) then
- text = string.sub(text, 1, -2)
- elseif Controls.check(pad, KEY_A) then
- Screen.freeImage(image)
- Screen.clear(BOTTOM_SCREEN)
- return text
- end
- end
- end
- Screen.flip()
- end
- Screen.waitVblankStart()
- Screen.refresh()
- Screen.debugPrint(5,5,"hello !", white, TOP_SCREEN)
- while true do
- Screen.waitVblankStart()
- Screen.refresh()
- Screen.debugPrint(5,20,"Press Start to quit, or A for magic!", white, TOP_SCREEN)
- pad = Controls.read()
- if oldPad ~= pad then
- if Controls.check(pad,KEY_START) then
- System.exit()
- elseif Controls.check(pad,KEY_A) then
- Screen.clear(TOP_SCREEN)
- word = keyboard("What's your name?")
- Screen.clear(TOP_SCREEN)
- Screen.debugPrint(5,5,"hello "..word.." !", white, TOP_SCREEN)
- end
- end
- Screen.flip()
- end
Advertisement
Add Comment
Please, Sign In to add comment