473,396 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

keyboard input intercept

Hello,
I am writing a shell in C.
I need to intercept Signals like CTRL+C or CTRL+D
and set to ignore them. This is on Unix, using gcc.
my goal is to avoid users escaping the shell with SIGINT
SIGQUIT signals using keyboard input.
Anyone could give me a little hint ?

thanks

Rick

Mar 2 '07 #1
8 4800
RJ45 <rj**@NOSPAMslacknet.comwrites:
I am writing a shell in C.
I need to intercept Signals like CTRL+C or CTRL+D
and set to ignore them. This is on Unix, using gcc.
my goal is to avoid users escaping the shell with SIGINT
SIGQUIT signals using keyboard input.
Anyone could give me a little hint ?
I'd recommend comp.unix.programmer as a place where you're likely
to get better answers to this question.
--
Peter Seebach on C99:
"[F]or the most part, features were added, not removed. This sounds
great until you try to carry a full-sized printout of the standard
around for a day."
Mar 2 '07 #2
RJ45 wrote:
Hello,
I am writing a shell in C.
I need to intercept Signals like CTRL+C or CTRL+D
and set to ignore them. This is on Unix, using gcc.
my goal is to avoid users escaping the shell with SIGINT
SIGQUIT signals using keyboard input.
Anyone could give me a little hint ?

thanks

Rick
Yes, methods are available to do this, but you should ask in a group
for your system or atleast comp.unix.programmer, since it is system
specific. Standard C itself only provides rudimentary facilities for
signal handling, but your system's C library will most likely provide
more facilities to accomplish what you want.

Mar 2 '07 #3
In article <sl*****************@slacknet.com>,
RJ45 <rj**@NOSPAMslacknet.comwrote:
>Hello,
I am writing a shell in C.
I need to intercept Signals like CTRL+C or CTRL+D
and set to ignore them. This is on Unix, using gcc.
my goal is to avoid users escaping the shell with SIGINT
SIGQUIT signals using keyboard input.
Anyone could give me a little hint ?
Let me be the first to say:

Off topic. Not portable. Cant discuss it here. Blah, blah, blah.

Useful clc-related links:

http://en.wikipedia.org/wiki/Aspergers
http://en.wikipedia.org/wiki/Clique
http://en.wikipedia.org/wiki/C_programming_language

However, I will point out, as a small hint, that ^C and ^D *aren't*
"signals". Grasping fully the implications of this will help greatly in
solving your underlying problem.

Mar 2 '07 #4
In article <11**********************@h3g2000cwc.googlegroups. com>,
santosh <sa*********@gmail.comwrote:
>RJ45 wrote:
>Hello,
I am writing a shell in C.
I need to intercept Signals like CTRL+C or CTRL+D
and set to ignore them. This is on Unix, using gcc.
my goal is to avoid users escaping the shell with SIGINT
SIGQUIT signals using keyboard input.
Anyone could give me a little hint ?

thanks

Rick

Yes, methods are available to do this, but you should ask in a group
for your system or atleast comp.unix.programmer, since it is system
specific. Standard C itself only provides rudimentary facilities for
signal handling, but your system's C library will most likely provide
more facilities to accomplish what you want.
But, as I pointed out, signal handling doesn't have anything to do with
it; *keyboard* handling does. I.e., OP certainly meant to write:

I need to intercept keys like CTRL+C or CTRL+D ...

Mar 2 '07 #5
Kenny McCormack wrote:
In article <11**********************@h3g2000cwc.googlegroups. com>,
santosh <sa*********@gmail.comwrote:
RJ45 wrote:
Hello,
I am writing a shell in C.
I need to intercept Signals like CTRL+C or CTRL+D
and set to ignore them. This is on Unix, using gcc.
my goal is to avoid users escaping the shell with SIGINT
SIGQUIT signals using keyboard input.
Anyone could give me a little hint ?

thanks

Rick
Yes, methods are available to do this, but you should ask in a group
for your system or atleast comp.unix.programmer, since it is system
specific. Standard C itself only provides rudimentary facilities for
signal handling, but your system's C library will most likely provide
more facilities to accomplish what you want.

But, as I pointed out, signal handling doesn't have anything to do with
it; *keyboard* handling does. I.e., OP certainly meant to write:

I need to intercept keys like CTRL+C or CTRL+D ...
Since he's trying to intercept key sequences for the purpose of signal
handling, it would be more portable to use the system's signal
handling facilities than attempting to manually interpret key
sequences as signals. The key sequences can vary from system to
system, but the signal types and method of handling are likely to be
more or less the same.

Also only few of the possible signals are mapped to keyboard
sequences. What if a signal is sent from another process, instead of
the user? Inspite of all this, some signals like SIGKILL can't be
ignored.

If the OP's shell's response to signals is not canonical for the
concerned platform, then potential users are likely to get annoyed
with his programme.

Mar 2 '07 #6
On Mar 2, 12:13 pm, RJ45 <r...@NOSPAMslacknet.comwrote:
Hello,
I am writing a shell in C.
I need to intercept Signals like CTRL+C or CTRL+D
and set to ignore them. This is on Unix, using gcc.
my goal is to avoid users escaping the shell with SIGINT
SIGQUIT signals using keyboard input.
Anyone could give me a little hint ?

thanks

Rick
If you are working on a PC, those key sequences are interperated in
the keyboard handler most likely a dll.
I've done some easy rewrites to just see if a key was pressed. Turbo
C 3.x had Kbhit() function that reported if a key was hit.

I suspect WinXP and beyond have further removed you from the hardware.

gm

Mar 2 '07 #7
GMM50 wrote:
On Mar 2, 12:13 pm, RJ45 <r...@NOSPAMslacknet.comwrote:
Hello,
I am writing a shell in C.
I need to intercept Signals like CTRL+C or CTRL+D
and set to ignore them. This is on Unix, using gcc.
my goal is to avoid users escaping the shell with SIGINT
SIGQUIT signals using keyboard input.
Anyone could give me a little hint ?

thanks

Rick

If you are working on a PC, those key sequences are interperated in
the keyboard handler most likely a dll.
Key sequences have nothing to do with signals. The fact that a few
keys are mapped to some common signals doesn't mean a program has to
mess around with the raw keyboard input to handle signals.
I've done some easy rewrites to just see if a key was pressed. Turbo
C 3.x had Kbhit() function that reported if a key was hit.
Proper signal handling must also take into account signals received
from other processes.
I suspect WinXP and beyond have further removed you from the hardware.
There's no need to do keyboard handling to implement response to
signals, not for an ordinary application anyway.

Mar 2 '07 #8
"santosh" <sa*********@gmail.comwrites:
GMM50 wrote:
>On Mar 2, 12:13 pm, RJ45 <r...@NOSPAMslacknet.comwrote:
Hello,
I am writing a shell in C.
I need to intercept Signals like CTRL+C or CTRL+D
and set to ignore them. This is on Unix, using gcc.
my goal is to avoid users escaping the shell with SIGINT
SIGQUIT signals using keyboard input.
Anyone could give me a little hint ?

If you are working on a PC, those key sequences are interperated in
the keyboard handler most likely a dll.
I think you mean if you're working under MS Windows (PCs can, and
often do, run other operating systems). The OP specifically said he's
using Unix, which doesn't have DLLs (at least not by that name).
Key sequences have nothing to do with signals. The fact that a few
keys are mapped to some common signals doesn't mean a program has to
mess around with the raw keyboard input to handle signals.
<OT>
On Unix-like systems, if a program doesn't perform any system-specific
actions, then typing Control-C will most likely cause a SIGINT signal
to be delivered to the current program.

The OP can either (a) use signal() (or some system-specific function
like sigaction()) to set up a handler for the signal, or (b) do some
system-specific stuff to reconfigure the system so that Control-C is
treated as an ordinary character.

The signal-handling method is probably simplest, since it leaves it up
to the OS (and the user's settings) to determine which characters send
which signals.
</OT>

The details are, of course, system-specific; I suggest asking in a
comp.unix.programmer -- but check <http://www.faqs.org/faqs/unix-faq/>
first.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Mar 2 '07 #9

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

Similar topics

2
by: Patricio Stegmann | last post by:
Hello, I'm trying to capture all keyboard events from some different web page layouts: framesets with different stuff, like flash or whatever ! The problem I am getting is that only focused...
0
by: Erik Edlund | last post by:
I am trying to find information about creating a Keyboard Hook or Keyboard Logger that works in XP SP2 and VB Express. My application must intercept input from a barcode reader without disturbing...
0
by: Ray | last post by:
I have English Windows XP Pro and Office 2003 Pro on my computer. When I enter data into fields of tables, queries and forms of Access 2003, it automatically switches to Chinese keyboard input. ...
7
by: Don Riesbeck Jr. | last post by:
I'm working on an application (OEM) using C# that utilizes input from a keyboard, and USB Barcode Scanner. The scanner is a HID Keyboard device, and input from it is sent to the system as if it...
7
by: jpierson | last post by:
Hi, I am tryin to create a keyboard hook that sends the keystroke ctrl + pause/break. I haven't used keyboard hooks before so I'm not too sure how to use them public int MyKeyboardProc(int...
1
by: Jeremi | last post by:
Is there anyway, using javascript or an activex script, to intercept keyboard entries on a page, such as the F keys?
1
by: den | last post by:
hoe I can to intercept the keyboard's button DEL? a code that work in IE and Firefox. thank
1
by: =?Utf-8?B?TXJOb2JvZHk=?= | last post by:
I want to do something similar to what some macro tools do, where they perform mouse/keyboard events on the user's machine , while intercepting the user's current keyboard/mouse events so that it...
8
by: BD | last post by:
How can I duplicate the behavior of the operating system shortcut keys in my application? For example, my windows form has 5 controls (textboxes), the operating system will pickup which control...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...

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.