0

I'm writing a python program for our handheld-scanner. We have to scan loads of barcodes, but I don't like to hit 'enter' all the time.

Is there anyway that you can say: while typing, if the string you are typing is exactly 20 chars, create a new input?

I can count the return value of raw_input(), but that's not exactly what I want.

Polichism
  • 224
  • 1
  • 7

1 Answers1

1

You can use this getch function.

A small utility class to read single characters from standard input, on both Windows and UNIX systems. It provides a getch() function-like instance.

Then you can simple use a loop to get 20 chars.

import sys
while 1:
    c=''
    while len(c) < 10:
        g = getch()
        sys.stdout.write(g)
        c += g
    print "\nYou said", c
sloth
  • 99,095
  • 21
  • 171
  • 219