non-blocking getkey?
Ulli Horlacher
framstag at rus.uni-stuttgart.de
Thu Dec 10 10:52:15 EST 2015
Ulli Horlacher <framstag at rus.uni-stuttgart.de> wrote:
> My idea now is: instead of raw_input() I use a get_paste() function, which
> reads input character for input character and after a (say) 1 s timeout it
> returns the string. Pasting a string with the mouse is rather fast, there
> should be no big delay between the characters.
>
> How can I implement such a get_paste() function?
> I need a non-blocking getkey() function.
I found a solution for Windows:
print("\nCopy&paste a filename or drag&drop a file into this window")
file = get_paste()
print('\n"%s"' % file)
def get_paste():
import msvcrt
c = msvcrt.getch()
if c == '\n' or c == '\r': return ''
paste = c
while msvcrt.kbhit():
c = msvcrt.getch()
if c == '\n' or c == '\r': break
paste += c
return paste
--
Ullrich Horlacher Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de
Universitaet Stuttgart Tel: ++49-711-68565868
Allmandring 30a Fax: ++49-711-682357
70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/
More information about the Python-list
mailing list