Solved

How to trap Alt+Tab & Ctrl+Esc keypress

Posted on 1997-11-06
7
299 Views
Last Modified: 2013-12-03
Hello,

I'm writing a Vision Software where I don't want the user to accidentally press the system keys (ie: alt+tab & 
ctrl+esc). How do I go about trapping these messages?

I'm writing my software in Microsoft's Visual C++ 5.0 targeted for Window's NT platform. I tried to enter the above keypresses in the accelerator table and use the TranslateAccelerator API but somehow, these keypress messages never get trapped.


Please Help.


Thank You
Vivien A.
0
Comment
Question by:vcl
7 Comments
 
LVL 1

Expert Comment

by:kburns102197
ID: 1408223
The method & functions necessary to trap these keys is dependent on the development language.    What language are you writing in?
0
 

Author Comment

by:vcl
ID: 1408224
Edited text of question
0
 
LVL 22

Expert Comment

by:nietod
ID: 1408225
I've been watching this question intently, because it is a problem I've been having to.  The fact you haven't gotten an answer is discouraging, it looks like there almost isn't away.  
One thing that makes this hard to do (as you may already know) is that windows does not pass the regular keydown, keyup, and character messages for these keys.  In fact, it appears to me that it sends no messages at all for these keys.  That seems a little unfair.  If this is true, then a message processing solution is out.  An approach that might work (I haven't tried) would be to use a hook.  It is possible to hook the keyboard with SetWindowsHookEx() using WH_KEYBOARD.

I have no experience in this area, so I'm not sure that the restrictions, if any, are.  But you might have the hook routine look for the keys and, if found, send a message, to your application.  This of course requires that the hook routine get notified for these keys.  I don't know if it is.

If you try this, I'd like to know what you find.
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Expert Comment

by:borov
ID: 1408226
Surely you can't do it without writing driver which intercepts these keystrokes. Setting hooks doesn't help, I've worked on the same problems a couple of years ago and had not found any simple solution. Try to search WEB for the driver.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1408227
What is the problem with hooks?  Is it that you don't get notification for these two keys?
0
 

Expert Comment

by:borov
ID: 1408228
No, you get notification on ALT as syskey. But when you press ALT-TAB - oops - you got nothing. Impossible to prevent the switching itself. I forgot many details, so dont ask me any details - I can get wrong :).
0
 
LVL 11

Accepted Solution

by:
alexo earned 100 total points
ID: 1408229
AFAIK, it is impossible to "steal" the ALT-TAB, etc. keystrokes from NT (95 is a different matter) but you can fudge it.

Whenever your window loses focus, just force it back.  (Of course, you'll have to deal with issues like message boxes, multiple-windows applications, etc. but it's doable).

One way: when your window gets a WM_KILLFOCUS message, do a SetFocus() back (maybe you'll also have to bring your window to the foreground and other stuff).
A WM_CAPTURECHANGED message is also a possible candidtate for "overriding".

Another way is to do it with global hooks -- SetWindowsHookEx().
Either use WH_CALLWNDPROC and look for focus switch messages, or use WH_CBT, look for HCBT_SETFOCUS and return 1 to disallow it.
See whichever works for you.

Note that there may be other caveats.  Spy++ is your friend.

0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

803 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