Mini keypad

Post Reply
Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Mini keypad

Post by Henko »

I use this keypad to enter or change text or numbers into buttons.
The keypad may be placed anywhere on the screen and disappears upon touching the enter key.
IMG_1231.jpeg
IMG_1231.jpeg (578.4 KiB) Viewed 3599 times

Code: Select all


graphics
init_keypad(100,190,50,1,1,0,1)
button "in" text "hit the button" at 200,10 size 300,40
do slowdown
  if bp("in") then button "in" text keypad$("Well?")
  until forever
end

' mini keypad,flexible location and size, preserves background
' upper case selection by fast hitting a key twice 
'
' xtop, ytop : left upper corner of the keypad
' bs : button size; keypad size is derived from it.
' R,G,B,alpha : background color of the keys
'
def init_keypad(xtop,ytop,bs,R,G,B,alpha)
ob=option_base() ! option base 1
dim kp.a$(44)
kp.dt=0.2        '*** wait time for 2nd "upper case" touch
restore
for i=1 to 44 ! read kp.a$(i) ! next i
data "1","2","3","4","5","6","7","8","9","0",chr$(57917)
data "q","w","e","r","t","y","u","i","o","p","/"
data "a","s","d","f","g","h","j","k","l","_",chr$(57909)
data "z","x","c","v"," ","b","n","m",",",".",chr$(57933)
name$="keypad"
page name$ set 
page name$ frame xtop,ytop,0,0
set buttons custom
if bs<20 then bs=20
sp=4 ! th=.5*bs+4 ! ww=11*bs+12*sp ! hh=th+4*bs+6*sp
fsize=.5*bs
draw font size fsize ! set buttons font size fsize
draw color 0,0,0 ! fill color .7,.7,.7
button "rec" title "" at 0,0 size ww,hh
fill color R,G,B ! fill alpha alpha
for k=1 to 44
  x=(k-1)%11+1 ! y=floor((k-1)/11)+1
  xp=(x)*sp+(x-1)*bs ! yp=th+(y-1)*bs+(y+1)*sp
  button k text kp.a$(k) at xp,yp size bs,bs
  next k
button "res" title "" at 0,0 size ww,th+4
page name$ hide ! page name$ frame xtop,ytop,ww,hh
set buttons default ! set buttons font size 20
draw font size 20 ! option base ob ! page "" set
end def

def keypad$(default$)
ob=option_base() ! option base 1
page "keypad" set ! page "keypad" show
a$=default$
do slowdown
  button "res" text a$
  la=len(a$)
  if bp(str$(11)) then a$=""
  if bp(str$(44)) then break
  if bp(str$(33)) and la>0 then a$=left$(a$,la-1)
  for i=1 to 44
    if bp("res") then a$=""
    if i=11 or i=33 or i=44 then continue
    if bp(str$(i)) then
      b$=kp.a$(i) ! time reset
      do
        if bp(str$(i)) then    '  check for upper case
          b$=chr$(asc(b$)-32) ! break
          end if
        until time()>kp.dt
      a$&=b$
      end if
    next i
  until forever
page "keypad" hide ! page "" set
option base ob
return a$
end def

def db ! debug pause ! end def
def bp(a$) = button_pressed(a$)


Post Reply