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.

2
  • See this:stackoverflow.com/a/575781/297323 Commented Sep 19, 2012 at 12:30
  • Can't you make the scanner send newlines after each barcode? This is a fairly common feature. Commented Sep 19, 2012 at 14:35

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.