Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

key board

edited September 2014 in Code Sharing Posts: 28

How do you make a pop up keyboard

Tagged:

Comments

  • IgnatzIgnatz Mod
    Posts: 5,396

    Try searching for keyboard in the search box above

  • dave1707dave1707 Mod
    Posts: 7,532

    @Ray_Spahn Do you mean how to make your very own keyboard, or how to make the Codea keyboard show/hide.

  • edited September 2014 Posts: 28

    @dave1707how to make your very own keyboard

  • dave1707dave1707 Mod
    Posts: 7,532

    @Ray_Spahn Here's something I threw together, maybe this will help.


    displayMode(FULLSCREEN) function setup() k1=keybrd(100,300) end function draw() background(40, 40, 50) fill(255) k1:draw() end function touched(t) k1:touched(t) end keybrd=class() function keybrd:init(x,y) self.caps=false self.size=50 self.x=x self.y=y self.tx=0 self.ty=0 self.key="" self.keys={{" ZXCVBNM,. "},{"ASDFGHJKL "},{"QWERTYUIOP "},{"1234567890 "}} end function keybrd:draw() for y=1,4 do for x=1,string.len(self.keys[y][1]) do fill(255) rect(self.x+x*self.size,self.y+y*self.size,self.size,self.size) fill(0) text(string.sub(self.keys[y][1],x,x), self.x+x*self.size+self.size/2,self.y+y*self.size+self.size/2) if y==2 and x==10 then -- return text("retn",self.x+x*self.size+self.size/2,self.y+y*self.size+self.size/2) end if y==2 and x==11 then -- space text("space",self.x+x*self.size+self.size/2,self.y+y*self.size+self.size/2) end if y==3 and x==11 then -- back space text("back\nspace",self.x+x*self.size+self.size/2,self.y+y*self.size+self.size/2) end if y==1 and (x==1 or x==11) then -- caps if self.caps then text("caps\n on",self.x+x*self.size+self.size/2,self.y+y*self.size+self.size/2) else text("caps\noff",self.x+x*self.size+self.size/2,self.y+y*self.size+self.size/2) end end end end fill(255) text(self.key,self.x+250,self.y+300) end function keybrd:touched(t) if t.state==ENDED then self.tx=math.floor((t.x-self.x)/self.size) self.ty=math.floor((t.y-self.y)/self.size) if self.tx<1 or self.tx>11 or self.ty<1 or self.ty>4 then return end if self.ty==1 and (self.tx==1 or self.tx==11) then -- capital key self.caps = not self.caps return end if self.ty==2 and self.tx==10 then -- return key self.key="" return end if self.ty==3 and self.tx==11 then -- backspace key self.key=string.sub(self.key,1,string.len(self.key)-1) return end if self.caps then self.key=self.key..string.sub(self.keys[self.ty][1],self.tx,self.tx) else print(self.tx,self.ty) self.key=self.key.. string.lower(string.sub(self.keys[self.ty][1],self.tx,self.tx)) end end end
  • edited September 2014 Posts: 28

    @dave1707 thank you sooooo much this is very helpful, and creative

Sign In or Register to comment.