Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- seleccion = image.load("imgXkey/cuadrado.png")
- tiempo = timer.new()
- minus = {
- {"q","w","e","r","t","y","u","i","o","p"},
- {"a","s","d","f","g","h","j","k","l","ñ"},
- {"mayus","z","x","c","v","b","n","m","esp","OK"},
- img = image.load("imgXkey/tecladominus.png")
- }
- mayus= {
- {"Q","W","E","R","T","Y","U","I","O","P"},
- {"A","S","D","F","G","H","J","K","L","Ñ"},
- {"num","Z","X","C","V","B","N","M","esp","OK"},
- img = image.load("imgXkey/tecladomayus.png")
- }
- num= {
- {"0","1","2","3","4","5","6","7","8","9"},
- {".",",","-","_","(",")","[","]","!","?"},
- {"minus","á","é","í","ó","ú","`","´","esp","OK"},
- img = image.load("imgXkey/tecladosimb.png")
- }
- peke= {
- {"7","8","9"},
- {"4","5","6"},
- {"1","2","3"},
- {"-","0","."},
- img = image.load("imgXkey/tecladopeke.png")
- }
- function xkeyboard(Xteclado,Yteclado,Xtexto,Ytexto,texto,comentario,tipo)
- local tmp = screen.toimage()
- local x=1
- local y=1
- local tecladoactual=minus
- if tipo == 1 then tecladoactual = peke end
- if texto == nil then texto = "" end
- if comentario == nil then comentario = "" end
- texto = tostring(texto)
- local pos = #texto
- function añadirletra(string,pos,letra)
- if pos < #string then return string.sub(string,1,pos)..letra..string.sub(string,pos+1,#string)
- elseif pos == #string then return string..letra end
- end
- tiempo:start()
- while true do
- controls.read()
- tmp:blit(0,0)
- if controls.press("right") then x=x+1 end
- if controls.press("left") then x=x-1 end
- if controls.press("up") then y=y-1 end
- if controls.press("down") then y=y+1 end
- if controls.press("r") and pos < #texto then pos = pos + 1 end
- if controls.press("l") and pos >0 and #texto >0 then pos = pos - 1 end
- if tipo == nil then
- if y>=4 then y=1 end
- if y<=0 then y=3 end
- if x>=11 then x=1 end
- if x<=0 then x=10 end
- elseif tipo == 1 then
- if y>=5 then y=1 end
- if y<=0 then y=3 end
- if x>=4 then x=1 end
- if x<=0 then x=1 end
- end
- if controls.press("cross") then
- if tecladoactual[y][x] != "mayus" and tecladoactual[y][x] != "minus" and tecladoactual[y][x] != "num" and
- tecladoactual[y][x] != "esp" and tecladoactual[y][x] != "OK" then
- if tipo == nil then texto = añadirletra(texto,pos,tecladoactual[y][x]); pos = pos+1; end
- if tipo == 1 and tecladoactual[y][x] == "-" and #texto == 0 then texto = "-"; pos = pos+1;
- elseif tipo == 1 and tecladoactual[y][x] != "-" then texto = añadirletra(texto,pos,tecladoactual[y][x]); pos = pos+1;
- elseif tipo == 1 and tecladoactual[y][x] == "." and string.match(texto,".") == nil then añadirletra(texto,pos,".") ; pos = pos+1; end end
- if tecladoactual[y][x] == "mayus" then tecladoactual = num
- elseif tecladoactual[y][x] == "num" then tecladoactual = minus
- elseif tecladoactual[y][x] == "minus" then tecladoactual = mayus
- elseif tecladoactual[y][x] == "OK" then break
- elseif tecladoactual[y][x] == "esp" then añadirletra(texto,pos," "); pos = pos +1 end
- end
- if controls.cross() then screen.print(Xtexto+screen.textwidth(comentario..string.sub(texto,1,pos)),Ytexto-1,"|") end
- if controls.press("square") and #texto > 0 and pos >0 then texto = string.sub(texto,1,pos-1)..string.sub(texto,pos+1,#texto); pos = pos -1; end
- if controls.press("triangle") and tipo == nil then texto = añadirletra(texto,pos," "); pos = pos +1 end
- if controls.press("circle") then texto = "" pos = 0 end
- if controls.press("select") then
- if tecladoactual == mayus then tecladoactual = num
- elseif tecladoactual == num then tecladoactual = minus
- elseif tecladoactual == minus then tecladoactual = mayus end
- end
- if math.abs(controls.analogx())>20 then Xteclado = Xteclado + controls.analogx()/15 end
- if math.abs(controls.analogy())>20 then Yteclado = Yteclado + controls.analogy()/15 end
- tecladoactual.img:blit(Xteclado,Yteclado)
- seleccion:blit(Xteclado+(21*x)-10,Yteclado+(21*y)-(9+y))
- screen.print(Xtexto,Ytexto,comentario..texto)
- if controls.press("start") then
- tmp:free()
- break
- end
- if not controls.cross() and tiempo:time() >= 0 and tiempo:time() < 500 then
- screen.print(Xtexto+screen.textwidth(comentario..string.sub(texto,1,pos)),Ytexto-1,"|")
- elseif tiempo:time() >= 1000 then tiempo:reset()
- end
- screen.flip()
- end
- x=nil; y=nil; tecladoactual=nil; pos=nil; tiempo:free();
- if tipo == nil then return texto;
- elseif tipo == 1 then return tonumber(texto);
- end
- end
Add Comment
Please, Sign In to add comment