473,698 Members | 2,524 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Keyboard interrupts

Hello !

I want to catch any event on a PC by the interrupts (C++ under Linux).
My first step is to catch everything from the keyboard. I have:

---------------------------------------------------

#include <iostream>
#include <csignal>
using namespace std;

void the_keyboard (int sig)
{
cout << "handling signal no. " << sig << endl;
}

main ()
{
int cont = 1;
while (cont) {
signal (1, the_keyboard); // catch interrupt No.1 (keyboard)
}
}

---------------------------------------------------

It do not works... If this part can work, after, I will add more signal
definition (for other events, mouse, etc...);

If anyone have an idea ?

Thanks,

Cyber
Jul 23 '05 #1
8 14170
Cyber wrote:
I want to catch any event on a PC by the interrupts (C++ under Linux).
My first step is to catch everything from the keyboard. I have:
[...]
It do not works... If this part can work, after, I will add more signal
definition (for other events, mouse, etc...);

If anyone have an idea ?


There is no way to do what you want using only Standard C++. Please
ask your platform-specific question in a newsgroup dedicated to your
platform (comp.os.linux. development.app s is probably it). They should
have an idea or two.

V
Jul 23 '05 #2
Cyber wrote:
I want to catch any event on a PC by the interrupts (C++ under Linux).
Your questions is about Linux, not C++, so you'd get much better results on
a Linux newsgroup.
while (cont) {
signal (1, the_keyboard); // catch interrupt No.1 (keyboard)
} It do not works... If this part can work, after, I will add more signal
definition (for other events, mouse, etc...);


What are you _really_ trying to do? If you want to affect keystrokes, you
should program to the layer of Linux that handles them the way you need. For
example, if you use X Windows (via Gnome, KDE, or the various others), then
you should research how their keyboard handlers work, and how to extend
them.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces
Jul 23 '05 #3
Victor Bazarov wrote:
There is no way to do what you want using only Standard C++. Please
ask your platform-specific question in a newsgroup dedicated to your
platform (comp.os.linux. development.app s is probably it). They should
have an idea or two.


However we must keep in mind that C++ provides <csignal>.


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #4
Cyber wrote:
Hello !

I want to catch any event on a PC by the interrupts (C++ under Linux).
My first step is to catch everything from the keyboard. I have:

---------------------------------------------------

#include <iostream>
#include <csignal>
using namespace std;

void the_keyboard (int sig)
{
cout << "handling signal no. " << sig << endl;
}

main ()
{
int cont = 1;
while (cont) {
signal (1, the_keyboard); // catch interrupt No.1 (keyboard)
}
}

---------------------------------------------------

It do not works... If this part can work, after, I will add more signal
definition (for other events, mouse, etc...);

If anyone have an idea ?

signal assigns a function handler to a signal, so you should use it once in the above.

Interrupt values are system-specific. Here is a program that handles ctrl-c by displaying
its int value:

#include <iostream>
#include <csignal>
void sigint_handler( int sig)
{
std::cout << "handling signal no. " << sig << "\n";
}
int main ()
{
using namespace std;

signal(SIGINT, sigint_handler) ;

while(true)
;
}

Of course you can displays the system-specific values of each of the standard ones with
this way:
#include <iostream>
#include <csignal>

int main ()
{
using namespace std;

cout<<"SIGABRT: "<<SIGABRT<<"\n "
<<"SIGFPE: "<<SIGFPE<< "\n"
<<"SIGILL: "<<SIGILL<< "\n"
<<"SIGINT: "<<SIGINT<< "\n"
<<"SIGSEGV: "<<SIGSEGV<<"\n "
<<"SIGTERM: "<<SIGTERM<<"\n ";
}
which in my system are:

C:\c>temp
SIGABRT: 22
SIGFPE: 8
SIGILL: 4
SIGINT: 2
SIGSEGV: 11
SIGTERM: 15

C:\c>

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #5
Ioannis Vranos wrote:
Victor Bazarov wrote:
There is no way to do what you want using only Standard C++. Please
ask your platform-specific question in a newsgroup dedicated to your
platform (comp.os.linux. development.app s is probably it). They should
have an idea or two.

However we must keep in mind that C++ provides <csignal>.


We must. Does it have anything to do with a keyboard?
Jul 23 '05 #6
Here is what the last draft of C90 was saying:
"4.7 SIGNAL HANDLING <signal.h>

The header <signal.h> declares a type and two functions and defines
several macros, for handling various signals (conditions that may be
reported during program execution).

The type defined is

sig_atomic_t

which is the integral type of an object that can be accessed as an
atomic entity, even in the presence of asynchronous interrupts.

The macros defined are

SIG_DFL
SIG_ERR
SIG_IGN

which expand to distinct constant expressions that have type
compatible with the second argument to and the return value of the
signal function, and whose value compares unequal to the address of
any declarable function; and the following, each of which expands to a
positive integral constant expression that is the signal number
corresponding to the specified condition:

SIGABRT abnormal termination, such as is initiated by the abort function

SIGFPE an erroneous arithmetic operation, such as zero divide or an
operation resulting in overflow

SIGILL detection of an invalid function image, such as an illegal
instruction

SIGINT receipt of an interactive attention signal

SIGSEGV an invalid access to storage

SIGTERM a termination request sent to the program

An implementation need not generate any of these signals, except as
a result of explicit calls to the raise function. Additional signals
and pointers to undeclarable functions, with macro definitions
beginning, respectively, with the letters SIG and an upper-case letter
or with SIG_ and an upper-case letter,/97/ may also be specified by
the implementation. The complete set of signals, their semantics, and
their default handling is implementation-defined; all signal values
shall be positive.
4.7.1 Specify signal handling

4.7.1.1 The signal function

Synopsis

#include <signal.h>
void (*signal(int sig, void (*func)(int)))( int);

Description

The signal function chooses one of three ways in which receipt of
the signal number sig is to be subsequently handled. If the value of
func is SIG_DFL , default handling for that signal will occur. If the
value of func is SIG_IGN , the signal will be ignored. Otherwise,
func shall point to a function to be called when that signal occurs.
Such a function is called a signal handler .

When a signal occurs, if func points to a function, first the
equivalent of signal(sig, SIG_DFL); is executed or an
implementation-defined blocking of the signal is performed. (If the
value of sig is SIGILL, whether the reset to SIG_DFL occurs is
implementation-defined.) Next the equivalent of (*func)(sig); is
executed. The function func may terminate by executing a return
statement or by calling the abort , exit , or longjmp function. If
func executes a return statement and the value of sig was SIGFPE or
any other implementation-defined value corresponding to a
computational exception, the behavior is undefined. Otherwise, the
program will resume execution at the point it was interrupted.

If the signal occurs other than as the result of calling the abort
or raise function, the behavior is undefined if the signal handler
calls any function in the standard library other than the signal
function itself or refers to any object with static storage duration
other than by assigning a value to a static storage duration variable
of type volatile sig_atomic_t . Furthermore, if such a call to the
signal function results in a SIG_ERR return, the value of errno is
indeterminate.

At program startup, the equivalent of

signal(sig, SIG_IGN);

may be executed for some signals selected in an implementation-defined
manner; the equivalent of

signal(sig, SIG_DFL);

is executed for all other signals defined by the implementation.

The implementation shall behave as if no library function calls the
signal function.

Returns

If the request can be honored, the signal function returns the
value of func for the most recent call to signal for the specified
signal sig . Otherwise, a value of SIG_ERR is returned and a positive
value is stored in errno .

Forward references: the abort function ($4.10.4.1).
4.7.2 Send signal

4.7.2.1 The raise function

Synopsis

#include <signal.h>
int raise(int sig);

Description

The raise function sends the signal sig to the executing program.

Returns

The raise function returns zero if successful, nonzero if unsuccessful."


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #7
> However we must keep in mind that C++ provides <csignal>.

Please develope your ideas.
Where do we go with the fact that C++ provides <csignal>?

Stephen Howe

Jul 23 '05 #8
Stephen Howe wrote:
Please develope your ideas.
Where do we go with the fact that C++ provides <csignal>?

That the question is about inside the limits of ISO C++.


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4643
by: Tomasz \Boruh\ Borowiak | last post by:
Does anybody have any idea how to write a c++ console application which simulates the mobile phone keyboard ? for Example: when i write SMS I hit 2 - I get "a" I hit 22 - I get "b" I hit 222 - I get "C"; Please help. thanks for all replays boruh
23
7737
by: herrcho | last post by:
What's the difference between STDIN and Keyboard buffer ? when i get char through scanf, i type in some characters and press enter, then, where do the characters go ? to STDIN or Keyboard buffer ? are they same ? thanks ^^
1
1192
by: yasin | last post by:
is it possible inputting characters from keyboard by codes.or can we use assemly interrupts in asp.net to press keyboard buttons by code.
0
1141
by: yasin | last post by:
is it possible inputting characters from keyboard by codes.or can we use assemly interrupts in asp.net to press keyboard buttons by code.
16
10927
by: dfaber | last post by:
Hi all, I have been searching for a keyboard and mouse tracker on linux. I've read solutions (watch at sourceforge) which look at /proc/interrupts to check keyboard or mouse activity. I also read one post where "watch" seems to have difficulty tracking usb keyboards and mice. So, I'm out of ideas here. My goal are: 1. Check keyboard activity. I'm not interested in logging which keys are pressed or record them.
4
3413
by: John Ladasky | last post by:
Hi there. The following minimal code in Python 2.3.4 works under Idle v. 1.0.3, but not under SciTE v. 1.66: from time import sleep try: while True: sleep(0.25) print ".",
6
547
by: skam | last post by:
hi i need to send an HEX String to the ps/2 port. i have a special keyboard connected to the ps/2 port and i want to send it some stuff to control his tone indicator. using c or c++ in linux os. how can i do? many thanks Gia
2
4001
by: anon856525 | last post by:
Hi, I'm trying to write a keyboard handle with Borland. I think the code below should work, but it doesn't compile. The problem is I cannot set the return of getvect() to a void interrupt (*)(), ie void interrupt (*old_int9)(); ....
3
3000
by: NaN | last post by:
I've been trying to use _kbhit() but it didn't do what I thought it would from books, "Detects whether a keypress is available for reading." Herbert Schildt says, "If the user has pressed a key, this function returns true(non-0), but does not read the character. If no keystroke is pending, kbhit() returns false (0)." Here is the test code,
0
8678
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7737
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5861
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2333
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.