[MS] Customizing the ways the dialog manager dismisses itself: Detecting the ESC key, first (failed) attempt - devamazonaws.blogspot.com
Suppose you want to distinguish between dismissing a dialog by pressing ESC and dismissing a dialog by clicking the Close button. One suggestion I saw was to call GetAsyncKeyState( VK_ ESCAPE) to check whether the ESC is down. In general, any time you see GetAsyncKeyState , you should be suspicious, since GetAsyncKeyState checks the state of the keyboard at the moment it is called, which might not be relevant to your window if it asynchronously lost keyboard focus, and which (from the point of view of your program) might even be from the future. Recall that the system maintains two types of keyboard states. One is the synchronous keyboard state, which represents the state of the keyboard as far as your program is aware. If your program received a WM_ KEYDOWN for the space bar, then GetKeyState will report that the space bar is pressed. Even if the user releases the space bar, GetKeyState will continue to report that the space bar is pressed until the program rece...