Easy to use Muiti Key press/release Functions
Rem Multibutton Key press and key release system by GTR
Rem Setup:
Sync on : Sync Rate 60 : autocam off : Backdrop on : color backdrop RGB(241,133,61) : Set Text size 20
rem Initialize the Button System
GoSub init_keys
rem Make a cube for test
Make object Cube 1,20
Color object 1,RGB(0,128,255)
Rem Camera
position camera 0.0 , 40.0 , -40.0
xrotate camera 40
rem some variables
TargetRotation# = 0.0
CurrentRotation# = 0.0
Rem thee loop:
Do
Rem Key Press test:
if KeyPress(44) then TargetRotation# = wrapvalue(TargetRotation# - 45)
if KeyPress(45) then TargetRotation# = wrapvalue(TargetRotation# + 45)
rem Key release Test
if KeyRel(30) then TargetRotation# = wrapvalue(TargetRotation# - 45)
if KeyRel(31) then TargetRotation# = wrapvalue(TargetRotation# + 45)
rem make the rotation smooth
CurrentRotation# = CurveAngle(TargetRotation#,CurrentRotation#,10)
yrotate object 1,CurrentRotation#
Text 10,10,"Press [A][S] To Test the Key Release Function"
Text 10,30,"Press [Z][X] To Test the Key Press Function"
sync
Loop
Rem ===================================================
init_Keys:
global dim NBS(255) as integer
global dim JNBS(20) as integer
return
function KeyRel(but)
Retn = 0
if keystate(but) = 1
NBS(but) = 1
else
IF NBS(but) = 1 then retn = 1
NBS(but) = 0
endif
endfunction retn
function KeyPress(but)
Retn = 0
if keystate(but) = 1
IF NBS(but) = 0 then retn = 1
NBS(but) = 1
else
NBS(but) = 0
endif
endfunction retn
Function JoyRel(but)
Retn = 0
if Joystick fire x(but) = 1
JNBS(but) = 1
else
IF JNBS(but) = 1 then retn = 1
JNBS(but) = 0
endif
EndFunction Retn