[Cs-dev] OT a bit, non-blocking keyboard input
| Date | 2006-04-11 11:59 |
| From | Iain Duncan |
| Subject | [Cs-dev] OT a bit, non-blocking keyboard input |
For my API project, I am currently doing a console input module, and
want to have non-blocking keyboard input in a thread, and preferably be
able to grab character either before or after the enter key. I got it to
work with the below but still have to hit enter. Can anyone tell me how
to alter that so that the key gets used right away? Also, is there a
better way of doing it if I would like the code to be portable to
non-unix systems? ( I tried using select as well, but couldn't get that
working without an enter key either. )
Thanks
Iain
// the below is working and not blocking,
// but still requires hitting enter
char key;
int byte_read;
fcntl( 0, F_SETFL, O_NONBLOCK );
fcntl( 0, F_SETFL, O_NDELAY );
while( !exit_now ){
// put in a delay sleep to share with other threads
usleep( 1000 );
byte_read = read( 0, &key, 1 );
if ( byte_read != -1 ){
if( key == 'x' ){
cout << "CONSOLE: issuing request shutdown message.\n";
server->push_msg( exit_msg );
}
}
}
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net |
| Date | 2006-04-11 19:18 |
| From | Anthony Kozar |
| Subject | Re: [Cs-dev] OT a bit, non-blocking keyboard input |
I think the best ways of doing this are going to be platform dependent. Do not use the C or C++ standard libraries. Use instead whatever native API is available for grabbing keyboard input on the OS you are using. For instance, on MacOS I would probably use the InputSprocket library which is good for grabbing arbitrary combinations of key-downs (including more than one at a time) and was designed for game developers. Just my $0.02. Anthony Iain Duncan wrote on 4/11/06 6:59 AM: > Can anyone tell me how > to alter that so that the key gets used right away? Also, is there a > better way of doing it if I would like the code to be portable to > non-unix systems? ( I tried using select as well, but couldn't get that > working without an enter key either. ) ------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |