2006-02-06 12:47:30

by pdn

[permalink] [raw]
Subject: trapping key press using signals


Hi,
How do i catch the signals generated by keypress using signals.



"SASKEN RATED Among THE Top 3 BEST COMPANIES TO WORK FOR IN INDIA - SURVEY 2005 conducted by the BUSINESS TODAY - Mercer - TNS India"

SASKEN BUSINESS DISCLAIMER
This message may contain confidential, proprietary or legally Privileged information. In case you are not the original intended Recipient of the message, you must not, directly or indirectly, use, Disclose, distribute, print, or copy any part of this message and you are requested to delete it and inform the sender. Any views expressed in this message are those of the individual sender unless otherwise stated. Nothing contained in this message shall be construed as an offer or acceptance of any offer by Sasken Communication Technologies Limited ("Sasken") unless sent with that express intent and with due authority of Sasken. Sasken has taken enough precautions to prevent the spread of viruses. However the company accepts no liability for any damage caused by any virus transmitted by this email


2006-02-06 17:37:04

by Ram Gupta

[permalink] [raw]
Subject: Re: trapping key press using signals

On 2/6/06, pdn <[email protected]> wrote:
>
> Hi,
> How do i catch the signals generated by keypress using signals.

Why do you need to catch keypress. Keypress generates interrupts which
are controlled by linux kernel. Then it transmits this character(s) to
the application. Hypothetically it is possible to setup some callback
with kernel so that whenver there is a keypress it handles it & then
invokes the call back. But I doubt if it is done currently.

Regards
Ram Gupta

2006-05-26 04:51:11

by Bharti

[permalink] [raw]
Subject: Re: trapping key press using signals


Hi,

With reference to your question : How to catch signals generated by
key press using signals i would like to share a piece of code which will
help you understand the concept more easily.

There are basically 3 ways to send singnals to Processes:
1.Using the keyboard : Like Ctrl-C , this causes the system to send an INT
signal (SIGINT) to the running process by default it causes the process to
immediately terminate. Another one is Ctrl-Z (SIGTSTP) which causes the
process to suspend execution and Ctrl-\ (SIGABRT) which does the same as
Ctrl-C but gives us some better flexibility.
Here is the piece of code snippet that causes the progeam to print the
string "Testing Code to understand" when a user presses Ctrl-C:

#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<signal.h>
void catch_int(sig_num)
{
/* re-set the signal handler again to catch_int, for next time*/
signal(SIGINT,catch_int);
printf("Testing Code to understand\n");
fflush(stdout);
}

int main(int argc,char* argv[])
{
/*set the INT (Ctrl-C) signal handler to 'catch_int' */
signal(SIGINT,catch_int);
/*now,lets get into an infinite loop of doing nothing.*/
for(;;)
pause();
}

The pause() system call causes the process to halt execution, until a signal
is received. It is suerly better than a 'busy wait' infinite loop.


2. Sending signals from the command Line: Like Kill
kill-<signal><PID>
If no signal name or number is specified, by default TERM signal is sent to
the process.
3. Using Susyem Calls: This way of generating signals is acheived by using
Kill system call (normal of sending a signal from one process to another).

Bye,
Bharti.

"pdn" <[email protected]> wrote in message
news:[email protected]...
> Hi,
> How do i catch the signals generated by keypress using signals.
>
>



"SASKEN RATED Among THE Top 3 BEST COMPANIES TO WORK FOR IN INDIA - SURVEY 2005 conducted by the BUSINESS TODAY - Mercer - TNS India"

SASKEN BUSINESS DISCLAIMER
This message may contain confidential, proprietary or legally Privileged information. In case you are not the original intended Recipient of the message, you must not, directly or indirectly, use, Disclose, distribute, print, or copy any part of this message and you are requested to delete it and inform the sender. Any views expressed in this message are those of the individual sender unless otherwise stated. Nothing contained in this message shall be construed as an offer or acceptance of any offer by Sasken Communication Technologies Limited ("Sasken") unless sent with that express intent and with due authority of Sasken. Sasken has taken enough precautions to prevent the spread of viruses. However the company accepts no liability for any damage caused by any virus transmitted by this email