Not sure if this was done before or not. Did a search on keyboard and there were pages and pages of results. But here is a small keyboard for anyone who needs one. The keys values can be changed to match your needs. The only keys hard coded are the RTN, SP, ← keys which correspond to return, space, backspace. Also, the x,y position of the keyboard can be modified. I didn’t put a whole lot of effort into this because everyone needs something different, so I’ll let you modify it to what you need.
EDIT: Added code to switch between lower case and upper case using the “cap” key.
displayMode(FULLSCREEN)
function setup()
value=""
k1=keybrd(0,100)
end
function draw()
background(40,40,50)
k1:draw()
if value~=nil then
text(value,WIDTH/2,HEIGHT-100)
end
end
function touched(t)
if t.state==BEGAN then
value=k1:touched(t)
end
end
keybrd=class()
function keybrd:init(x,y)
self.keys="-/:;()$&@.,?!' ..STUVWXYZ1234567890ABCDEFGHIJKLMNOPQR"
self.size=42
self.str=""
self.x=x-self.size
self.y=y-self.size
self.caps=false
self.hide=false
end
function keybrd:draw()
background(40,40,50)
if self.hide then
return
end
local c=0
for y=1,3 do
for x=1,18 do
c=c+1
fill(255)
rect(x*self.size+self.x,y*self.size+self.y,self.size,self.size)
fill(255,0,0)
local val=string.sub(self.keys,c,c)
if c==15 then val="CAP" end
if c==16 then val="SP" end
if c==17 then val="<--" end
if c==18 then val="RTN" end
if not self.caps then
val=string.lower(val)
end
text(val,x*self.size+self.size/2+self.x,y*self.size+self.size/2+self.y)
end
end
text(self.str,WIDTH/2,self.y+200)
end
function keybrd:touched(t)
if self.hide then
return
end
if t.state==BEGAN then
local tx=math.floor((t.x-self.x)/self.size)
local ty=math.floor((t.y-self.y)/self.size)
local pos=(ty-1)*18+tx
local val=string.sub(self.keys,pos,pos)
if not self.caps then
val=string.lower(val)
end
if pos==15 then
self.caps= not self.caps
return
end
if pos==17 then
self.str=string.sub(self.str,1,string.len(self.str)-1)
return
end
if pos==18 then
local str1=self.str
self.str=""
return(str1)
end
self.str=self.str..val
end
end