Results 1 to 3 of 3

Thread: Waiting for keypress...

  1. #1

    Thread Starter
    Addicted Member scotty85_2000's Avatar
    Join Date
    Feb 2001
    Posts
    198

    Waiting for keypress...

    How would I pause my coding at certain intervals to wait for the user to press the spacebar? Also how can I pause the coding for a certain amount of time before continuing?
    Thanking you in advance...
    100 posts... All of them have been "How Do I's", "Can You's", "HELP ME!!'s"...
    Still, at least they've been relevant..

  2. #2
    trophyfish
    Guest
    Put in an endless loop untill a keyboard event happens.

    x=0
    do while x<>1

    if keyboard event happens then
    x=1
    end if

    loop

  3. #3
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    It would be better to do this. If you just make an endless loop, you may end up locking the system completely.
    VB Code:
    1. 'in a module
    2. Public Declare Function GetKeyState Lib "user32" (ByVal vKey As Long) As Long
    3. Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    4. Public Const VK_SPACE As Long = &H20
    5.  
    6. 'wherever you want to wait until space is hit, add this
    7. Do Until GetKeyState(VK_SPACE) And &H8000: DoEvents: Loop
    8.  
    9. 'to stop your program for a certain period of time, like to halt while displaying something
    10. Sleep 5000 'stop for 5 seconds
    I'm baaaack...
    VB5 Professional Edition, VC++ 6
    Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se

    I feel special because I finally figured out how to loop midis: Post link
    I'm a fanatic too

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width