help for using msvcrt.kbhit() with Python 2.3 editors?

Discussion in 'Python' started by dbrown2@yahoo.com, Aug 13, 2003.

  1. Guest

    I'm having some trouble using kbhit inside the editor enviroments. I'm
    using win2000 with Python2.3 and win32all v157 versions.

    Any pointer on how this should be handled would be appreciated. Is
    there another non-blocking way to detect a key press?

    Here's the code that is causing the trouble. If I run this by
    double-clicking then it works as expected. But if I run from IDLE or
    PythonWin it basically never returns. msvcrt.kbhit() always returns 0
    as far as I can tell by adding print statements. I can't confirm it
    but I seem to recall this worked at least with the PythonWin editor
    environment under my previous Python 2.2 setup.

    ###########
    import serial # access to serial port
    import time # sleep command
    import msvcrt # detect keyboard key press events

    ser = serial.Serial(0, 4800, timeout=0.25)
    data = ''
    while not msvcrt.kbhit():
    buf = ser.read(10)
    if buf <> '': print buf
    #time.sleep(1)
    data = data + buf # concatenate buf onto data
    ser.close()
    ###########

    -- David
     
    , Aug 13, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rasmus B. Nielsen

    kbhit in console?

    Rasmus B. Nielsen, Aug 28, 2003, in forum: Java
    Replies:
    1
    Views:
    2,461
    Harald Hein
    Aug 29, 2003
  2. DevarajA

    something like kbhit

    DevarajA, Jun 9, 2005, in forum: C++
    Replies:
    8
    Views:
    3,778
    Alan Johnson
    Jun 10, 2005
  3. Dick Moores
    Replies:
    11
    Views:
    586
    Gabriel Genellina
    Oct 30, 2007
  4. Virgil Stokes

    Module msvcrt for Python

    Virgil Stokes, Dec 18, 2011, in forum: Python
    Replies:
    0
    Views:
    205
    Virgil Stokes
    Dec 18, 2011
  5. alb
    Replies:
    5
    Views:
    148
    xDog Walker
    Apr 30, 2013
Loading...

Share This Page