Solved

Disable ALT Key

Posted on 2004-09-03
3
314 Views
Last Modified: 2010-04-01
Hello all,

Is there a way to disable the ALT key in a console program?  I only want to disable the key from working in the console window, not in all windows.  It will be running on a Win 2K system.

Thanks,
Tony
0
Comment
Question by:fattumsdad
  • 2
3 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 11986798
Hm, let me put it like that - what do you want to achieve by that? There might be a way doing that differently, using a less stony trail than I can see now doing that...
0
 
LVL 1

Author Comment

by:fattumsdad
ID: 11986864
Actually, I made a mistake in my question...  what I should have said was, the CTRL key.  My mind was on ALT for some reason :)
I want to stop CTRL-C from terminating the application.  
0
 
LVL 86

Accepted Solution

by:
jkr earned 300 total points
ID: 11990156
>>I want to stop CTRL-C from terminating the application

Oh, then, just use a handler that catches that:

#include <windows.h>
#include <signal.h>
#include <iostream>
using namespace std;

void __cdecl CtrlCHandler ( int nSig) {

 // do nothing
 cout << "CTRL+C has been pressed" << endl;

 signal  (   SIGINT,     CtrlCHandler);
 signal  (   SIGBREAK,   CtrlCHandler);
}

int main () {

 signal  (   SIGINT,     CtrlCHandler);
 signal  (   SIGBREAK,   CtrlCHandler);

 while ( true) Sleep ( 100);
}
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now