Reading multiple event sources with plain Tcl.

1 view
Skip to first unread message

Jean-Claude Pitre

Mar 10, 1999, 3:00:00 AM3/10/99
Hello all,

I would like to read two event sources in plain tcl (tcl8.0.4 on win95):
The keyboard and the midi input. I used Tcl_CreateEventSource() to add
the midi input. This seems to work. FOr the keyboard, I set an event
handler on stdin (with Tcl_CreateChannelHandler()) and use
Tcl_DoOneEvent() to handle the incoming events.

The problem is that the event handler for the stdin channel seems to
think that there is always some input waiting to be read, even if
nothing was typed. My event handler is called for no reason and blocks
trying to read the channel. It seems to me the program should block in
Tcl_WaitForEvent() until there is either something in stdin or the midi
input. Instead, the setUpProc for the channel always says there is
something to read and the GetMessage() (win95) in Tcl_WaitFOrEvent() is
never called to actually wait.

Any ideas?

Jean-Claude Pitre

Paul Duffin

Mar 11, 1999, 3:00:00 AM3/11/99

The problem is that there is no support in Tcl for console channels
which is what stdin should be connected to. I think that a lot of work
has been done for 8.1 to add support for this and other different
channels. This is not a problem on Unix because the operating system
provides an abstraction layer (file descriptors) which make consoles
(tty), files, sockets etc work in a very similar way. Unfortunately
M$ have not done this on Windows so every 'channel' has its own API
and has to have special support added to it.

Paul Duffin
DT/6000 Development Email:
IBM UK Laboratories Ltd., Hursley Park nr. Winchester
Internal: 7-246880 International: +44 1962-816880

Scott Redman

Mar 11, 1999, 3:00:00 AM3/11/99
Paul is correct, the console and serial port channels have
been rewritten in 8.1, and pipes should work fine as well.
The standard channels have also be hooked up to the appropriate
channel type (except sockets) and wish will hook them up as
well (if they are valid channels, such as a pipe, file, or
serial port, but not consoles because Windows always disconnects
them before launching the wish.exe). The code should be available
in 8.1b2 (or you can get it now from the CVS repository now).

-- Scott Redman
-- Scriptics Corporation

Paul Duffin wrote in message <>...

Reply all
Reply to author
0 new messages