It is currently Fri Oct 18, 2019 8:11 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Detect keyboard on-the-fly
PostPosted: Thu Aug 22, 2019 3:11 pm 
Offline
User
User

Joined: Sat May 29, 2010 11:46 am
Posts: 86
Location: UK
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:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Detect keyboard on-the-fly
PostPosted: Thu Aug 22, 2019 6:50 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Tue Sep 22, 2009 10:41 pm
Posts: 441
Code:
;*********************************************************************************************
LapLimit = ElapsedMilliseconds() + 5000
Repeat
 Delay(10)
 ExamineKeyboard()
 ClearScreen(Rgb(31, 63, 191) )
 FlipBuffers()
Until KeyboardPushed(#PB_Key_All) Or LapLimit < ElapsedMilliseconds()


Top
 Profile  
Reply with quote  
 Post subject: Re: Detect keyboard on-the-fly
PostPosted: Fri Aug 23, 2019 4:52 pm 
Offline
User
User

Joined: Sat May 29, 2010 11:46 am
Posts: 86
Location: UK
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:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Detect keyboard on-the-fly
PostPosted: Sat Aug 24, 2019 3:00 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Tue Sep 22, 2009 10:41 pm
Posts: 441
You maybe could access to your hardrive less often than previously.
Code:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Detect keyboard on-the-fly
PostPosted: Mon Aug 26, 2019 11:03 am 
Offline
User
User

Joined: Sat May 29, 2010 11:46 am
Posts: 86
Location: UK
Point taken in - many thanks.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 18 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye