Re: Main Loop, IO Channels and my CLI
- From: Chris Vine <chris cvine freeserve co uk>
- To: gtk-list gnome org
- Subject: Re: Main Loop, IO Channels and my CLI
- Date: Sun, 25 Jun 2006 23:28:39 +0100
On Sunday 25 June 2006 21:41, Øystein Johansen wrote:
> Tor Lillqvist wrote:
[snip]
> > Ah, I forgot to answer this part. I am afraid you might run into
> > difficulty in doing this on Win32.
> >
> > Or maybe it isn't that hard? There is an API SetConsoleMode(), and
> > mode bits like "ENABLE_ECHO_INPUT" and "ENABLE_LINE_INPUT", so maybe
> > it's actually quite similar to Unix, and you can do
> > character-at-a-time input, and your own echo processing. Maybe all you
> > need to do is something like
> >
> > GetConsoleMode (GetStdHandle (STD_INPUT_HANDLE), &mode);
> > mode &= ~(ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT);
> > SetConsoleMode (GetStdHandle (STD_INPUT_HANDLE), mode);
> >
> > and it will Just Work?
>
> Wow! I just tried this, and it does indeed Just Work! Thanks. I must
> handle all the characters like backspace and return and so on, but it
> works...
>
> But, it doesn't work on linux.... How can I get character-at-a-time
> input from a linux console?
If you are not using an event based toolkit such as GDK/GTK+ for handling the
keyboard, then you will have to code on a platform specific basis.
If you want to code for a Linux/Unix console and you are using the glib main
loop then the easiest thing is to use curses with non-blocking input (see the
cbreak() and nodelay() calls) and poll it in a timer event you have set up
with g_timeout_add(). If you are feeling adventurous you can dispense with
curses and use the termios/tcgetattr()/tcsetattr() interface directly and set
up the console that way.
If you have no other reason to use the glib main loop (and there are plenty of
reasons why you might want to use it), you can make your own program loop
with select() and an appropriate timeout which polls the keyboard; or if all
you are interested in is keyboard events, you can put curses in single
extraction (cbreak) mode but with blocking input (or the equivalent with
termios) and use that as your event loop.
Chris
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]