Hi folks,
Just a small utility example of using @IDKEYDOWN to detect arrow key input in a window program.
Useful to copy and paste if you ever need to do this .. :)
' GWS Example using @idkeydown to detect Keyboard input
def w:window
def wstyle,i:int
def sW,sH,varW,varH:int
def a$:string
wstyle = @minbox
sW = 300
sH = 200
' open a window ..
window w,0,0,sW,sH,wstyle,0,"Creative Basic",messages
setwindowcolor w,rgb(0,0,50)
centerwindow w
control w,"B,Exit,0,(sH-25)* 0.7,sW,25,0,1"
setfont w, "Arial", 10, 700
frontpen w,RGB(240,240,250)
a$ = "Press any Arrow key"
gettextsize w, a$, varW, varH
move w,(sW-varW)/2,(sH-varH)*0.82
print w,a$
' setup for large text ..
setfont w, "Arial", 22, 700
frontpen w,RGB(180,180,250)
run = 1
WAITUNTIL run = 0
CLOSEWINDOW w
END
SUB messages
select @class
case @idclosewindow
run = 0
case @idcontrol
if @controlID = 1 then run = 0
case @idkeydown
select 1
case (@code = 0x26) :' up arrow
a$="Up"
case (@code = 0x28) :' down arrow
a$="Down"
case (@code = 0x25) :' left arrow
a$="Left"
case (@code = 0x27) :' right arrow
a$="Right"
default
a$="Press any Arrow key"
endselect
gettextsize w, a$, varW, varH
move w,(sW-varW)/2,(sH-varH)/3
print w,a$
case @idkeyup
rect w, 0,0,sW,sH*0.7,rgb(0,0,50),rgb(0,0,50)
endselect
RETURN
It always strikes me how neat Creative Basic is for creating simple (and not so simple) programs.
Best wishes, :)
Graham