Differenze tra le versioni di "Attendere in un'applicazione 'a riga di comando' la pressione del tasto 'Invio'"
Riga 7: | Riga 7: | ||
− | ==Uso | + | ==Uso della funzione ''Input''== |
− | Questa modalità prevede | + | Questa modalità prevede il semplice uso della funzione ''Input'' in varie possibilità che di seguito si espongono. |
− | |||
− | + | ===Uso di Input ed una variabile stringa=== | |
− | |||
− | ===Uso di Input ed una variabile=== | ||
Questa modalità fa semplicemente uso di ''Input'' ed una variabile di tipo stringa: | Questa modalità fa semplicemente uso di ''Input'' ed una variabile di tipo stringa: | ||
+ | '''Public''' Sub Main() | ||
+ | |||
+ | Dim s As String | ||
+ | |||
+ | <FONT Color=#B22222>Input s</font> | ||
+ | |||
+ | Print "Tasto premuto !" | ||
+ | |||
+ | '''End''' | ||
+ | Se, però, si vuole conoscere anche la lettera del tasto premuto, si utilizzerà un ciclo di attesa: | ||
'''Public''' Sub Main() | '''Public''' Sub Main() | ||
Riga 34: | Riga 41: | ||
Dim s As String | Dim s As String | ||
− | + | ||
− | + | <FONT Color=#B22222>Input #File.In, s</font> | |
− | + | ||
− | + | Print "Tasto premuto !", s | |
− | |||
− | Print "Tasto premuto !" | ||
'''End''' | '''End''' | ||
Riga 52: | Riga 57: | ||
fl = Open "<FONT Color=#B22222>/dev/stdin</font>" For Read | fl = Open "<FONT Color=#B22222>/dev/stdin</font>" For Read | ||
− | + | ||
− | + | <FONT Color=#B22222>Input #fl, s</font> | |
− | + | ||
− | + | fl.Close | |
− | + | ||
− | Print "Tasto premuto !" | + | Print "Tasto premuto !", s |
− | + | ||
'''End''' | '''End''' | ||
Riga 71: | Riga 76: | ||
fl = Open "<FONT Color=#B22222>/dev/tty</font>" For Read | fl = Open "<FONT Color=#B22222>/dev/tty</font>" For Read | ||
− | + | <FONT Color=#B22222>Input #fl, s</font> | |
− | + | ||
− | + | fl.Close | |
− | + | ||
− | Print "Tasto premuto !" | + | Print "Tasto premuto !", s |
'''End''' | '''End''' | ||
Riga 89: | Riga 94: | ||
fl = Open "<FONT Color=#B22222>/dev/pts/...</font>" For Read | fl = Open "<FONT Color=#B22222>/dev/pts/...</font>" For Read | ||
− | + | <FONT Color=#B22222>Input #fl, s</font> | |
− | + | ||
− | + | fl.Close | |
− | + | ||
− | Print "Tasto premuto !" | + | Print "Tasto premuto !", s |
'''End''' | '''End''' | ||
Riga 106: | Riga 111: | ||
fl = Open "<FONT Color=#B22222>/proc/self/fd/0</font>" For Read | fl = Open "<FONT Color=#B22222>/proc/self/fd/0</font>" For Read | ||
− | + | ||
− | + | <FONT Color=#B22222>Input #fl, s</font> | |
− | + | ||
− | + | fl.Close | |
− | + | ||
− | Print "Tasto premuto !" | + | Print "Tasto premuto !", s |
'''End''' | '''End''' |
Versione delle 04:51, 16 ott 2015
Per determinare in un'applicazione "a riga di comando" (quindi lanciata da Terminale) l'attesa della pressione del tasto Invio, potranno essere utilizzate diverse modalità.
Indice
Uso dell'evento Application_Read()
Questa modalità è mostrata anche in questa pagina della WIKI, alla quale si rinvia, e si basa sulla sollevazione dell'evento _Read() della Classe Application.
Uso della funzione Input
Questa modalità prevede il semplice uso della funzione Input in varie possibilità che di seguito si espongono.
Uso di Input ed una variabile stringa
Questa modalità fa semplicemente uso di Input ed una variabile di tipo stringa:
Public Sub Main() Dim s As String Input s Print "Tasto premuto !" End
Se, però, si vuole conoscere anche la lettera del tasto premuto, si utilizzerà un ciclo di attesa:
Public Sub Main() Dim s As String Do Input s Loop Until s <> Null Print "Tasto premuto !" End
Uso della proprietà File.In
Questa modalità fa uso in modo diretto della proprietà File.In che ritorna lo standard input del flusso:
Public Sub Main() Dim s As String Input #File.In, s Print "Tasto premuto !", s End
Uso del file-device /dev/stdin
Questa modalità fa uso del file-device /dev/stdin che dovrà essere aperto in lettura:
Public Sub Main() Dim fl As File Dim s As String fl = Open "/dev/stdin" For Read Input #fl, s fl.Close Print "Tasto premuto !", s End
Uso del file-device /dev/tty
Questa modalità fa uso del file-device /dev/tty che dovrà essere aperto in lettura:
Public Sub Main() Dim fl As File Dim s As String fl = Open "/dev/tty" For Read Input #fl, s fl.Close Print "Tasto premuto !", s End
Uso del file-device /dev/pts/...
Questa modalità fa uso del file-device /dev/pts/... specifico del Terminale nel quale è stata lanciata la nostra applicazione a riga di comando. Lo specifico file-device di tipo pts, è identificato con un numero che però andrà preventivamente individuato e dovrà essere aperto in lettura:
Public Sub Main() Dim fl As File Dim s As String fl = Open "/dev/pts/..." For Read Input #fl, s fl.Close Print "Tasto premuto !", s End
Uso del file /proc/self/fd/0
Questa modalità fa uso del file /proc/self/fd/0 che dovrà essere aperto in lettura:
Public Sub Main() Dim fl As File Dim s As String fl = Open "/proc/self/fd/0" For Read Input #fl, s fl.Close Print "Tasto premuto !", s End