Fixing the “break on F12” problem

A few years ago, I was writing a Delphi app that used the F12 key for something or other (I think it was to pop up a dialog showing the current record ID). And at some point, it stopped working on my computer. The users had no problems, but on my development machine, F12 broke into Delphi and popped up the CPU window (!), and after I resumed, my app had never seen the F12 keystroke. I couldn’t find anything in the Delphi docs to explain it, and I finally just gave up and made the app respond to both F12 (which the users were already used to) and F11 (so I could test).

Deepak Shenoy just posted about this very same issue, including the fix. Turns out it’s not a Delphi problem at all; it’s Windows 2000 (and later) that hijack F12, which is probably why I didn’t see the problem at first (I started developing that app on Windows 95, and later switched to Windows 2000 — that would probably be when F12 stopped working). Deepak’s post includes a link to an MS support page that explains how to tell Windows to hijack a different key instead (I like his suggestion of using Pause).

I just tested this with a .NET app in Visual Studio, and F12 only forces a break if you have the native debugger attached (by attaching to an already-running program with Debug > Processes and checking the “Native” checkbox). Normally you would only have the CLR debugger attached (this is what Debug > Start does), so F12 isn’t hijacked and your program works as expected.

Leave a Reply

Your email address will not be published. Required fields are marked *