#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2005
    Posts
    5
    Rep Power
    0

    Checking for user input.


    I'm trying to make a function that will wait for x amount of time, then beep. However, I want the program to break the x amount of time loop if the user presses a key.

    My problem is raw_input() waits for the user to return before it will count it. That screws up the while loop and allows it to stay for longer than 30 seconds. I'm new to python, so could someon help me see what I should do. I tried some other functions like sys.stdin and someone reccomended _Getch, but I couldn't figure those out. I think it may be possible to fix it by tweaking the structure, but I can't see how.


    import time
    import sys

    def act(wait):
    for i in range(0,5):
    till = time.time()
    till = till + wait
    while till >= time.time() :
    if ' ' == raw_input() :
    till = till - ( wait + 1 )

    print 'beep'

    act(5)

    ~capiCrimm
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2005
    Posts
    5
    Rep Power
    0
    This is about as far as I am now. The timer seems to work fine, but I can't get it

    python Code:
     
    import time
    import msvcrt
     
    def act(times,wait):
        for i in range(0,times):
            till = time.time()
            till = till + wait  
            while till >= time.time() :
                if msvcrt.kbhit():
                    msvcrt.getche();
                    till = time.time()sjjjjad
                    break
            print 'beep'
     
    act(5,5)


    An even simplier explaination might be I just want a timer that stops when A. a user presses a key, or B. after `x' about of time.

IMN logo majestic logo threadwatch logo seochat tools logo