Solved

Disable ALT Key

Posted on 2004-09-03
3
331 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

856 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