Just a small simple example of text entry using a timer based update function.
The original code is Lee's for DarkBasic Standard, but it has a Dark Basic Professional twist so isn't backward compatible *as-is*.
It wouldn't take much to convert however.
Rem * Title : Keyboard Entry
Rem * Author : DBS-LB
Rem * Date : October 2001
rem ===============================================
rem DARK BASIC EXAMPLE PROGRAM 24
rem ===============================================
rem This program handles Keyboard Entry
rem -----------------------------------------------
#constant TRUE 1
#constant FALSE 0
#constant VK_BACKSPACE 8
#constant UPDATETIME 10
#constant CURSORFLASH 30
type _TIMER
fOld as float
fCur as float
fDur as float
fAccum as float
bSwitch as boolean
endtype
type _STRING
new as string
update as string
endtype
global time as _TIMER
global buffer as _STRING
global cursor as _STRING
rem A nice font
set text font "Arial" : set text size 32
time.fOld = timer()
rem Main loop
do
gosub updateTime
if time.fAccum >= UPDATETIME
time.bSwitch=true
gosub updateKeyBuffer
if bUpdate = CURSORFLASH
gosub updateCursor
bUpdate = 0
else
inc bUpdate
endif
endif
rem Show Entry Buffer
cls rgb(64,64,64)
center text 320,200,"PERFECT KEYBOARD ENTRY"
text 160,240,buffer.update+cursor.update
rem End loop
loop
updateKeyBuffer:
rem Build line string
buffer.new = entry$()
for i=1 to len(buffer.new)
if asc(mid$(buffer.new,i))=VK_BACKSPACE
buffer.update=left$(buffer.update,len(buffer.update)-1)
else
buffer.update=buffer.update+mid$(buffer.new,i)
endif
next i
clear entry buffer
return
updateCursor:
rem Make simple cursor
if cursor.update="" then cursor.update="|" else cursor.update=""
return
function updateTime()
time.fCur = timer()
time.fDur = time.fCur - time.fOld
time.fOld = time.fCur
if time.bSwitch
time.fAccum = time.fDur
time.bSwitch=false
else
time.fAccum = time.fAccum + time.fDur
endif
endfunction