Disabling the Alt-Tab key combination

WEBINAR: On-demand webcast

How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >

The simplest way to achieve this is to use the RegisterHotKey function. By calling this function from within your process you take precedence over the O/S. The WM_HOTKEY message that is generated by the specified key combination will be re-directed to the your processes message queue. To block the hotkey, dont process the WM_HOTKEY message that is sent to your queue. Below I have copied a constructor and destructor that demonstrate this action.

// Call the RegisterHotKey function when the application 
// is instantiated to block the ALT-TAB combination
// Note:  The m_nHotKeyID is a int which specifies the hotkey 
//        ID, the hotkey id is programmer defined
CMainFrame::CMainFrame()
{
 m_nHotKeyID = 100;

 BOOL m_isKeyRegistered = RegisterHotKey(GetSafeHwnd(), m_nHotKeyID,
  MOD_ALT, VK_TAB);

 ASSERT(m_isKeyRegistered != FALSE);
}


//lets remove the hotkey block when the application is destroyed
CMainFrame::~CMainFrame()
{
 BOOL m_iskeyUnregistered = UnregisterHotKey(GetSafeHwnd(), m_nHotKeyID);
 ASSERT(m_isKeyUnregistered != FALSE);
}
There you have it, the simplest way to block the ALT-TAB without writing a VxD.

One last thing, the hotkey block will continue as long as your application is running. When your process terminates the hotkey will return to its original functionality.



Comments

  • crash with release build

    Posted by Legacy on 12/22/2003 12:00am

    Originally posted by: Sam

    It seem that App with RegisterHotKey function will crash with release build upon second time pressing the hotkey. Who can help? Thanks!

    Reply
  • API

    Posted by Legacy on 07/08/2003 12:00am

    Originally posted by: Mobeen

    I want to disable IE toolbar in my Application

    Reply
  • Disabling the Alt-Tab key combination

    Posted by Legacy on 08/11/2002 12:00am

    Originally posted by: Aamod Joshi

    How to control all the KB messages

    Reply
  • Does not work with Direct Input 8.0

    Posted by Legacy on 05/01/2002 12:00am

    Originally posted by: Robert

    Hello,

    Direct Input (DirectX 8.0) does not seem to allow ALT+TAB to be captured in the application (hotkey and global low level hook methods were tested). Allow though, the HotKey or hook does effect all of the other application in the Desktop until the application is ended.

    Any suggestions?

    Reply
  • TAB Key

    Posted by Legacy on 12/24/2001 12:00am

    Originally posted by: Abhijeet Sheorey

    Hi,
    
    

    I am facing a serious problem in my project. I want to disable a TAB key I've written a code in PreTranslateMessage
    Function. It's Working properly but if the previous key pressed is a Shift Key and after that if a tab key is pressed it dosen't work. So how to disable a tab key.

    I want a Shift + Tab key combination in my project ( Data Entry Project ). But I don't want Tab key. Can u please help me out.

    Thanks Abhijeet.

    Reply
  • How make the virus !!!!????

    Posted by Legacy on 06/28/2001 12:00am

    Originally posted by: Buggy

    Прива, я Бугги я хочу узнать как можно сделать вирус хотябы самый маленький на VC++, чтобы он записывал себя в конец какогонибудь EXE или COM файла.
    
    

    Спасибо за помощь !!!! Буг.

    Reply
  • ALT+F4 and others in Win 9x

    Posted by Legacy on 03/14/2001 12:00am

    Originally posted by: J.

    I was using the command, SystemParametersInfo(SPI_SCREENSAVERRUNNING, 1, (PVOID)1, 0);
    to disable alt+esc, alt+tab and ctl+alt+del

    However, I also need to get rid of alt+F4 so the user can not close the program.

    I tried using the code posted here (altering it for F4 not Tab), but it doesn't seem to work with my SystemParametersInfo code. I can only use one or the other. I am just getting in to visual programming with a mild background in C++. Any hints, suggestions...preferably something that's not too difficult. This is for a school project, and we are told to learn Visual C++ as we go. A task that is easier said than done (at least for me).

    Yes, the RegisterHotKey did work for Alt+F4 in a Win 9x environment. It did not however, work for alt+tab.


    Reply
  • How about WINLOGO+TAB and WINLOGO+ALT+TAB

    Posted by Legacy on 09/26/1999 12:00am

    Originally posted by: P. Kournetas

    I have used your code and it works fine...
    
    

    How can I trap and disable the following compinations:

    1) WINLOGO+TAB

    2) WINLOGO+ALT+TAB

    Reply
  • How to process a WM_HOTKEY in MFC?

    Posted by Legacy on 08/14/1999 12:00am

    Originally posted by: Alvin Sia

    Instead of the existing process that Windows do when encountered ALT+TAB, I would like to do another process, say invoking a hidden application. How should I implement WM_HOTKEY keyboard event in an MFC application?

    Reply
  • It does not work on DirectX based application.

    Posted by Legacy on 07/22/1999 12:00am

    Originally posted by: Kim, Hyoun Woo

    The way of using RegisterHotKey API doesn't work on DirectX based application.

    How do I make it disable ALT+TAB in DirectX based application?

    >> I've used SystemParametersInfo API also, but it's doesn't work too.

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • The software-defined data center (SDDC) and new trends in cloud and virtualization bring increased agility, automation, and intelligent services and management to all areas of the data center. Businesses can now more easily manage the entire lifecycle of their applications and services via the SDDC. This Aberdeen analyst report examines how a strong foundation in both the cloud and internal data centers is empowering organizations to fully leverage their IT infrastructure and is also preparing them to be able …

  • Learn which Mobile Development Platforms scored the highest in the current Forrester Wave. This report details the research findings about how well vendors fulfilled the 32 criteria to help you select the right partner for your mobile development platform needs. Download a free copy of the report compliments of Kinvey, a Progress company.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date