Solved

Disable ALT Key

Posted on 2004-09-03
3
297 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
Comment Utility
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
Comment Utility
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
Comment Utility
>>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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

771 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

8 Experts available now in Live!

Get 1:1 Help Now