Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to do "press any key to continue"?

1,952 views
Skip to first unread message

koffee

unread,
Feb 1, 2008, 2:00:31 PM2/1/08
to
Hi,

Can anyone suggest a simple way to do "press any key to continue" in
Tcl?

Thanks!

Larry W. Virden

unread,
Feb 1, 2008, 2:52:14 PM2/1/08
to
On Feb 1, 2:00 pm, koffee <luke...@gmail.com> wrote:
> Can anyone suggest a simple way to do "press any key to continue" in
> Tcl?

http://wiki.tcl.tk/14693 - Reading a single character from the
keyboard from Tcl...

koffee

unread,
Feb 1, 2008, 3:32:26 PM2/1/08
to
On Feb 1, 2:52 pm, "Larry W. Virden" <lvir...@gmail.com> wrote:
> On Feb 1, 2:00 pm, koffee <luke...@gmail.com> wrote:
>
> > Can anyone suggest a simple way to do "press any key to continue" in
> > Tcl?
>
> http://wiki.tcl.tk/14693- Reading a single character from the
> keyboard from Tcl...

THanks!

But I didn't expect it would be so complicated.

Derek Philip

unread,
Feb 1, 2008, 4:34:54 PM2/1/08
to
Whats wrong with

puts "Press any key to continue
gets stdin

ZB

unread,
Feb 1, 2008, 4:36:18 PM2/1/08
to
Dnia 01.02.2008 Derek Philip <derek....@tesco.net> napisał/a:

> Whats wrong with
>
> puts "Press any key to continue
> gets stdin

The wrong is, that it should be "Press Enter/Return to continue" rather... ;)
--
ZB

David Gravereaux

unread,
Feb 1, 2008, 6:20:21 PM2/1/08
to

On windows, that's a console setting. Even with 'fconfigure stdin
-buffering none', the commandline editor for the console itself is still
in cooked mode rather than raw.

I could have sworn a raw/cooked switch for the console channel driver
has come up in discussions before. It would be easy to do. IOW, place
stty options in the channel driver.

Why aren't they there now?

Neil Madden

unread,
Feb 2, 2008, 8:47:50 AM2/2/08
to
David Gravereaux wrote:
> ZB wrote:
>> Dnia 01.02.2008 Derek Philip <derek....@tesco.net> napisał/a:
>>
>>> Whats wrong with
>>>
>>> puts "Press any key to continue
>>> gets stdin
>>
>> The wrong is, that it should be "Press Enter/Return to continue"
>> rather... ;)
>
> On windows, that's a console setting. Even with 'fconfigure stdin
> -buffering none',

This one always gets me: -buffering sets the *output* buffering only, so
has absolutely no effect on stdin. I wish that had been named
-outputbuffering or something, as I frequently make this mistake. Of
course, Tcl buffers all input until you gets/read it.

the commandline editor for the console itself is still
> in cooked mode rather than raw.
>
> I could have sworn a raw/cooked switch for the console channel driver
> has come up in discussions before. It would be easy to do. IOW, place
> stty options in the channel driver.
>
> Why aren't they there now?

http://tip.tcl.tk/160 - has been in Vote: Pending status for a very long
time.

-- Neil

Gerry

unread,
Feb 3, 2008, 4:25:18 AM2/3/08
to
On 1 Feb, 20:32, koffee <luke...@gmail.com> wrote:
> On Feb 1, 2:52 pm, "Larry W. Virden" <lvir...@gmail.com> wrote:
>
> > On Feb 1, 2:00 pm, koffee <luke...@gmail.com> wrote:
>
> > > Can anyone suggest a simple way to do "press any key to continue" in
> > > Tcl?
>
> >http://wiki.tcl.tk/14693-Reading a single character from the

> > keyboard from Tcl...
>
> THanks!
>
> But I didn't expect it would be so complicated.

A simpler way is to adapt the following code posted by Bryan Oakley in
response to a question of mine 2 or 3 weeks ago

Gerry

------- The following was by Bryan Oakley

Here's code to show how you can trap all keypresses, reporting back
the
keysym, keycode, unicode character and keyboard state. In this
example
nothing ever appears in the text widget. Remove ";break" from the
binding to have the widget reflect what you typed.

This is by no means the only way to accomplish this task. You might
also
want to read up on bindtags. With just a couple of lines of code you
can
swap in or out whole sets of bindings.


proc main {} {
text .t -wrap word -yscrollcommand [list .vsb set]
scrollbar .vsb -command [list .t yview]
pack .vsb -side right -fill y
pack .t -side left -fill both -expand true

# The "break" is to inhibit the default behavior
bind .t <Any-KeyPress> {keyPress %k %K %s %A;break}
}

proc keyPress {keycode keysym state unicode} {
puts "you pressed a key:\
keycode=$keycode keysym=$keysym\
state=$state unicode=$unicode"
}

main

-------------------------------

Fabian Kreutz

unread,
Apr 4, 2008, 4:54:17 AM4/4/08
to
Hello!

I have the same problem but with the additional constraint, that stdin
is not a terminal, i.e. stty will not work. stdin is a pipe and I just
can't turn of the line buffering.

Any ideas there?

Bye, Fabian

--
Das Wer klobt seinen Meister!

Alexandre Ferrieux

unread,
Apr 4, 2008, 5:58:25 AM4/4/08
to
On Apr 4, 10:54 am, Fabian Kreutz <fab...@fs-maphy.uni-hannover.de>
wrote:

>
> I have the same problem but with the additional constraint, that stdin
> is not a terminal, i.e. stty will not work. stdin is a pipe and I just
> can't turn of the line buffering.

That's an entirely different problem: if you're using a pipe or socket
and [read $ch 1] doesn't return, it means that the byte was not
written by the writer. Your read side won't be able to change a bit of
this.

Now if you can put your fingers inside the guts of the writer, a
frequent mistake is a lack of flushing. If it is written in Tcl too,
it' s just a matter of [flush] or [fconfigure -buffering none]. For C
it is fflush/setvbuf.

-Alex

sleb...@gmail.com

unread,
Apr 4, 2008, 6:08:52 AM4/4/08
to
On Apr 4, 4:54 pm, Fabian Kreutz <fab...@fs-maphy.uni-hannover.de>
wrote:
> Hello!

>
> Larry W. Virden <lvir...@gmail.com> wrote:
>
> > On Feb 1, 2:00 pm, koffee <luke...@gmail.com> wrote:
> > > Can anyone suggest a simple way to do "press any key to continue" in
> > > Tcl?
> >http://wiki.tcl.tk/14693- Reading a single character from the

> > keyboard from Tcl...
>
> I have the same problem but with the additional constraint, that stdin
> is not a terminal, i.e. stty will not work. stdin is a pipe and I just
> can't turn of the line buffering.
>
> Any ideas there?
>

The hard part is because the stdin is a terminal. Otherwise turning
off "line buffering" is easy:

fconfigure stdin -translation binary

but remember to use [read] instead of [gets]. To do a "press any key"
type thing for ordinary channels simply do:

read stdin 1

Or you can use the event loop:

fileevent stdin readable {
#do what you want after keypress
}

Fabian Kreutz

unread,
Apr 4, 2008, 11:18:43 AM4/4/08
to
Hello!

>> stty will not work. stdin is a pipe and I just
>> can't turn of the line buffering.

> Now if you can put your fingers inside the guts of the writer, a


> frequent mistake is a lack of flushing.

Ah, ok.
The writer is my own very first erlang program. I can't explain why it
wouldn't send, but I'll investigate further into that direction.

Stupid me, I tested with 'cat <<eof | ./simple.tcl' and forgot that now
cat will do the line buffering...

Thanks also for the second answer.

0 new messages