Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make a choice without press enter

Status
Not open for further replies.

paskali

Programmer
Apr 6, 2012
13
IT
Hi all, i have a simple question, please read the following code:
Code:
#A simple script that print my name or my surname
proc main {} {
    set choice;
    puts "What do you want to see printed on the screen?";
    puts "";
    puts "a: Pasquale";
    puts "b: Frega";
    puts "";
    ?
    if {$choice=="a"} {
        puts "Pasquale";
    } elif {$choice=="b"} {
        puts "Frega";
    }
}
main;
My question is simple, i want simply to press 'a' or 'b' without press return and then i want to see my name or my surname printed on the screen. What might i write on the place of question mark?
Thanks!
 
I use cygwin on windows xp, i have solved by:
[CODDE]#A simple script that print my name or my surname
proc main {} {
puts "What do you want to see printed on the screen?";
puts "";
puts "a: Pasquale";
puts "b: Frega";
puts "";
exec /bin/stty raw <@stdin;
set choice [read stdin 1];
exec /bin/stty -raw <@stdin;
if {$choice=="a"} {
puts "Pasquale";
} elseif {$choice=="b"} {
puts "Frega";
}
}
main;[/CODE]

However it seems a bit hard in windows native system without cygwin. Moreover some keys (e.g. arrow keys) do not work properly on the control of the behaviour of the script.
I will make some other tests.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top