Page 1 of 1

Detect keyboard on-the-fly

Posted: Thu Aug 22, 2019 3:11 pm
by epog10
I want to rotate three or four 'idle' pictures, each for about ten seconds, until interrupted by a keyboard press.

However whatever I try in terms of timing does not interrupt the sequence like it should. It may or may not work. it may require multiple key presses. All rather untidy.

Unfortunately the rather excellent keyboard.pb example that comes with purebasic does not include a timer. Is there an example of this?

Can't get to work whether with Delay(x) or a Timer, whether with Window or Screen functions.

Guess what I want is:-

Code: Select all

Back:Load picture or sprite
	  Display it
	  Start the timing
	  Is a key pressed? --------- Exit the loop
	  At timer end, update required picture
	  Goto Back
Regards,
epog10

Re: Detect keyboard on-the-fly

Posted: Thu Aug 22, 2019 6:50 pm
by Olliv

Code: Select all

;*********************************************************************************************
LapLimit = ElapsedMilliseconds() + 5000
Repeat
 Delay(10)
 ExamineKeyboard()
 ClearScreen(Rgb(31, 63, 191) )
 FlipBuffers()
Until KeyboardPushed(#PB_Key_All) Or LapLimit < ElapsedMilliseconds()

Re: Detect keyboard on-the-fly

Posted: Fri Aug 23, 2019 4:52 pm
by epog10
Of course it makes sense to chop the delay up to under reaction time!

It ended up like this, with iDLE and aNS pre-set:-

Code: Select all

Procedure IDLE()
  Repeat
    Delay(10)
    ExamineKeyboard()
    LoadSprite(#Sprite_0, aNS)
    DisplaySprite(#Sprite_0, 0, 0)
    FlipBuffers()
    If L < ElapsedMilliseconds()
      iDLE = iDLE + 1
      If iDLE > 5 : iDLE = 1 : EndIf
      aNS = "C:\SIdle\Thepic" + Str(iDLE) + ".jpg"
      L = ElapsedMilliseconds() + 10000    
    EndIf
  Until KeyboardPushed(#PB_Key_All)
EndProcedure
Thank you very much for putting me right.

Regards,
epog10

Re: Detect keyboard on-the-fly

Posted: Sat Aug 24, 2019 3:00 pm
by Olliv
You maybe could access to your hardrive less often than previously.

Code: Select all

Procedure IDLE()
LoadSprite(#Sprite_0, aNS)
Repeat
   Delay(10)
   ExamineKeyboard()
   DisplaySprite(#Sprite_0, 0, 0)
   FlipBuffers()
   If L < ElapsedMilliseconds()
      iDLE = iDLE + 1
      If iDLE > 5 : iDLE = 1 : EndIf
      aNS = "C:\SIdle\Thepic" + Str(iDLE) + ".jpg"
      LoadSprite(#Sprite_0, aNS)
      L = ElapsedMilliseconds() + 10000
   EndIf
Until KeyboardPushed(#PB_Key_All)
EndProcedure

Re: Detect keyboard on-the-fly

Posted: Mon Aug 26, 2019 11:03 am
by epog10
Point taken in - many thanks.