Getting main loop to recognize escap key?
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Getting main loop to recognize escap key?




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Getting main loop to recognize escap key?  
James Johnson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-17-04 12:45 AM


I have a main.cpp running in a continuous loop. I have two files open and I'
ve been stopping the program with control-c. Is this the correct way to stop
 a unix program? I'd
like to get the loop to see the escape key (without polling for it). Or, how
 can I respond to control-c in the program so that I can close files etc.?

thanks,
Jim







[ Post a follow-up to this message ]



    Re: Getting main loop to recognize escap key?  
Måns Rullgård


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-17-04 12:45 AM

James Johnson <jjjhnson2-1779231@yahoo.com> writes:

> I have a main.cpp running in a continuous loop. I have two files open
> and I've been stopping the program with control-c. Is this the correct
> way to stop a unix program? I'd like to get the loop to see the escape
> key (without polling for it). Or, how can I respond to control-c in
> the program so that I can close files etc.?

man sigaction

Ctrl-C generates a SIGINT.

--
Måns Rullgård
mru@inprovide.com





[ Post a follow-up to this message ]



    Re: Getting main loop to recognize escap key?  
Wayne C. Morris


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-17-04 12:45 AM

In article <yw1x4qiofvs2.fsf@ford.inprovide.com>,
Måns Rullgård <mru@inprovide.com> wrote:

> James Johnson <jjjhnson2-1779231@yahoo.com> writes:
> 
>
> man sigaction
>
> Ctrl-C generates a SIGINT.

Not necessarily.  That seems to be the default on Linux and Mac OS X, but
many of the Unix systems I've worked on use DEL as the default intr key.
To change it to control-C, add "stty intr '^C'" to your login script.





[ Post a follow-up to this message ]



    Re: Getting main loop to recognize escap key?  
Måns Rullgård


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-17-04 12:45 AM

"Wayne C. Morris" <wayne.morris@this.is.invalid> writes:

> In article <yw1x4qiofvs2.fsf@ford.inprovide.com>,
>  Måns Rullgård <mru@inprovide.com> wrote:
> 
>
> Not necessarily.  That seems to be the default on Linux and Mac OS X, but
> many of the Unix systems I've worked on use DEL as the default intr key.
> To change it to control-C, add "stty intr '^C'" to your login script.

If the OP had such a system, he wouldn't be using ctrl-c to stop his
program.

--
Måns Rullgård
mru@inprovide.com





[ Post a follow-up to this message ]



    Re: Getting main loop to recognize escap key?  
James Johnson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-17-04 12:45 AM

On Tue, 14 Dec 2004 21:51:41 +0100, Måns Rullgård <mru@inprovide.com> wrote:

>James Johnson <jjjhnson2-1779231@yahoo.com> writes:
> 
>
>man sigaction
>
>Ctrl-C generates a SIGINT.

I got control-c to work great using SIGINT. But I'm still wondering if you c
an get a unix C main loop to wake up on hitting a key on the keyboard?

Jim






[ Post a follow-up to this message ]



    Re: Getting main loop to recognize escap key?  
Måns Rullgård


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-17-04 12:45 AM

James Johnson <jjjhnson2-1779231@yahoo.com> writes:

> On Tue, 14 Dec 2004 21:51:41 +0100, Måns Rullgård <mru@inprovide.com> wrot
e:
> 
>
> I got control-c to work great using SIGINT. But I'm still wondering
> if you can get a unix C main loop to wake up on hitting a key on the
> keyboard?

Sure, just twiddle the mode of your tty properly, and use select().

--
Måns Rullgård
mru@inprovide.com





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 01:04 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register