Wait Keyboard OR Click

BlitzPlus Forums/BlitzPlus Beginners Area/Wait Keyboard OR Click

ThePict(Posted 2013) [#1]
Any tips on how I can WaitKey and WaitClick at the same time?
I have thought of the endless While Not.. or Repeat...Until but they stop everything so I can't update my graphics.

Any suggestions or tips?


Midimaster(Posted 2013) [#2]
You talking about two different things. If you you use any Wait...() command, the execution will be stopped and graphics will not be updated. That is the sense of the Wait....() commands:

If you want this, a combination of Key and Mouse is not difficult:
Graphics 800,600
SetBuffer BackBuffer()
Cls

Text 100,100,MilliSecs()
Flip 0
action%=WaitKeyOrMouse()
Text 100,200,"and clicked too with action=" + action
Flip 0
WaitKeyOrMouse()
End

Function WaitKeyOrMouse%()
     Repeat 
         If MouseHit(1) Then Return 1
         If MouseHit(2) Then Return 2
         If MouseHit(3) Then Return 3
         For i%=0 To 255
             If KeyHit(i) Return i
         Next 
     Forever
End Function 




If you want to wait for such an event and the program should continue, you could use it this way:

Graphics 800,600
SetBuffer BackBuffer()
Global LastAction%
Repeat
     Cls

     Text 100,100,MilliSecs()
     action% = WaitKeyOrMouse()
     If action
          LastAction=action
     EndIf
     Text 100,200,"and clicked too with action=" + LastAction
     Flip 0
Forever
End

Function WaitKeyOrMouse%()
         If MouseHit(1) Then Return 1
         If MouseHit(2) Then Return 2
         If MouseHit(3) Then Return 3
         For i%=0 To 255
             If KeyHit(i) Return i
         Next 
        Return 0
End Function 



As a third solution you could use the Event() system of BlitzPlus.


ThePict(Posted 2013) [#3]
I ended up making a function that Returns 0 unless the specific key or mouse button has been clicked. I call the function repeatedly during my animation giving the graphics priority, but remembering any interaction from user to update game.
My code looks really clunky and inefficient but it works very smoothly, a long string of If KeyHit(..) then keyed$=".." because the scancode has to be turned into ascii... Every key used needs its own If Then statement. Good job our computers can do it all in a flash nowadays.

Thanks for your tips and example.