Fog Creek Software
Discussion Board

Selectively disabling Alt-F4

I usually Alt-F4 just about everything in sight but I don't want to do it for the programs that take forever to start, but accidents do happen and I Alt-F4 them.

I would be interested to know if there are any shareware or freeware that diables the Alt-F4 of programs like Photoshop, Illustrator, and other heavy-weight applications that takes a long time to initialize.

Friday, June 25, 2004

you can capture alt+f4 within applications that you wrote, but I'm not sure if you can "block" it for other applications.

Friday, June 25, 2004

This is possible if you write a DLL that installs a system wide Windows hook. This involves some Windows API knowledge, and SetWindowsHookEx() tricks.

Hooks are hairy and it can get messy, but I guess technically it could be done.

Friday, June 25, 2004

For an example of a keyboard hook, check out the source to my Morse Code Beeper:

I think you could adapt that code to monitor which application the Alt-F4 came from (either from checking the window title or from the window class, etc.) and toss out the Alt-F4 for those applications.  To toss a keystroke you return "1" instead of calling CallNextHookEx and returning its value; this prevents the keystroke from propagating down the hook chain and from reaching the application in question.

If I recall correctly, you would want to use a "low-level keyboard hook" (supported on NT-based versions of Windows only), since it lets you examine the message and toss it out before it gets posted to a message queue.  I do not believe that a non low-level hook would work in this case, thus, I don't think this would be very easy or even possible if you are on 95/98/Me.

Hope that helps.

Monday, June 28, 2004

*  Recent Topics

*  Fog Creek Home