Solved

How to trap Alt+Tab & Ctrl+Esc keypress

Posted on 1997-11-06
7
297 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 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

16 Experts available now in Live!

Get 1:1 Help Now