2014-12-20 14:21 GMT+01:00 Gabriele Battaglia <iz4...@libero.it>:

> Ciao a tutti.
> Ho questo script che funziona bene sotto Windows, ma, a causa dell’assenza
> di MSCVRT, non posso portare sotto Mac o Linux.
>
> Qualcuno ha qualche idea sul come poterlo modificare per far sì che
> funzioni anche sotto questi 2 sistemi operativi?
>
> ***
> # -*- Coding: UTF8 -*-
> # Utility di lettura tastiera 20/06/2014
> # Grazie agli amici della lista Python.
> # Versione 1.0
>
> import msvcrt, time
>
> def key(attesa=99999, msg=""):
>     ''' Attende per il numero di secondi specificati
>     se tempo e' scaduto, o si preme un tasto, esce.
>     msg e' il messaggio da mostrare.
>     Restituisce il tasto premuto. '''
>     if msg != "": print msg,
>     t = time.time(); a = ""
>     while (time.time() - t <= attesa):
>         if msvcrt.kbhit(): a = msvcrt.getch()
>         if a != "": break
>         time.sleep(0.025)
>

Devi impostare stdin in modalità cbreak e quindi usare select.select per
attendere che l'utente scriva qualcosa.

> [...]


Ciao   Manlio
_______________________________________________
Python mailing list
Python@lists.python.it
http://lists.python.it/mailman/listinfo/python

Rispondere a