I saw some posts about this from 2014, but didn’t seem like there was much follow up. Is there anyway to display a keyboard with only numbers? Thanks in advance.
@tr333 As far as I know, there isn’t. But if you’re just after a numeric keypad in a program you’re writing, you can write your own.
Incase anyone needs this:
--numebr keyboard
numInp={}
function numbpad()
spriteMode(CORNER)
sprite(asset.documents.numpad,0,0,375,216)
spriteMode(CENTER)
strokeWidth(0)
fill(220)
font("Vegur")
fontSize(28)
k=0
--draws 0 button
if CurrentTouch.state == BEGAN and CurrentTouch.pos.x > (8+(123)) and CurrentTouch.pos.x<(248) and CurrentTouch.pos.y > (2) and CurrentTouch.pos.y<(48) then
fill(216)
numInp[#numInp+1] = k
sleep(.1)
else
fill(255)
end
rect(131, 3,113,46)
fill(216)
rect(6,(3),113,46)
fill(0)
text("0",179,10)
--delete button
if CurrentTouch.state == BEGAN and CurrentTouch.pos.x > (254) and
CurrentTouch.pos.x<(369) and CurrentTouch.pos.y > (2) and CurrentTouch.pos.y<(48) then
table.remove(numInp, #numInp)
print(table.concat( numInp, "" ))
sleep(.1)
end
--draws 1-9
for i =1,3 do
for j=0,2 do
k=k+1
--draws buttons 1-9
if CurrentTouch.state == BEGAN and CurrentTouch.pos.x > (8+(j*123)) and
CurrentTouch.pos.x<(121+(j*123)) and CurrentTouch.pos.y > (218-(i*54)) and CurrentTouch.pos.y<(266-(i*54))then
fill(216)
rect(6+(j*122),218-(i*54),120,48)
--set key to number clicked
numInp[#numInp+1] = k
sleep(.1)
else
fill(255)
rect(8+(j*123),218-(i*54),113,46)
end
--text for numbers
fill(0)
text(j+1,56+(j*124),172)
text(j+4,56+(j*124),172-54)
text(j+7,56+(j*124),172-108)
end
end
end
For the sprite I just used a screenshot of the Apple numberpad.
Thanks!
@tr333 To format the code, you need to put ~~~ (three tildes) on a line before and after the code. I added them for you. You can edit the post and see what I did.
It’s a little bit tied in to my other classes, but I wrote a keypad UI interface a few years’ back. It would need a bit of work to make it standalone, but it wouldn’t be impossible to do so. It’s available on github.
Here’s something I threw together. I didn’t put much into it cause I don’t know how it’s going to be used and I’m not going to spend a lot of time on it to make it universal.
displayMode(FULLSCREEN)
function setup()
k1=keypad(WIDTH/2,HEIGHT/2)
ans=""
end
function draw()
background(149, 223, 203)
k1:draw()
fill(0)
text(ans,WIDTH/2,HEIGHT-100)
end
function touched(t)
k1:touched(t)
end
keypad=class()
function keypad:init(x,y)
self.tab={"C","","=","-","0",".","1","2","3","4","5","6","7","8","9"}
self.x=x
self.y=y
self.nbr=""
end
function keypad:draw()
pushStyle()
rectMode(CENTER)
fontSize(30)
fill(0)
rect(self.x,self.y,210,320)
v=0
for y=1,5 do
for x=1,3 do
v=v+1
fill(255)
ellipse(self.x+x*60-120,self.y+y*60-180,60)
fill(0)
text(self.tab[v],self.x+x*60-120,self.y+y*60-180)
end
end
fill(255)
stroke(0)
strokeWidth(8)
rect(self.x,self.y+180,210,50)
fill(0)
fontSize(25)
text(k1.nbr,self.x,self.y+180)
popStyle()
end
function keypad:touched(t)
if t.state==BEGAN then
v=0
for y=1,5 do
for x=1,3 do
v=v+1
if t.x>self.x+x*60-150 and t.x<self.x+x*60-90 and
t.y>self.y+y*60-210 and t.y<self.y+y*60-150 then
if self.tab[v]=="C" then
self.nbr=string.sub(self.nbr,1,#self.nbr-1)
elseif self.tab[v]=="=" then
ans=self.nbr
self.nbr=""
elseif self.tab[v]=="-" and #self.nbr>0 then
-- ignore -
else
self.nbr=self.nbr..self.tab[v]
end
end
end
end
end
end