Solved

How to trap Alt+Tab & Ctrl+Esc keypress

Posted on 1997-11-06
7
302 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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