Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to trap Alt+Tab & Ctrl+Esc keypress

Posted on 1997-11-06
7
Medium Priority
?
305 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

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 300 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

609 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