Any reason ALT might not work?

Started by
2 comments, last by Sean_Seanston 14 years, 9 months ago
Using a windowed DirectX application, I can't get the ALT key to work. You're supposed to use the VK_MENU virtual key for Win32, right? Whenever I try to get something like ALT + T to do something it just results in an error beep. It just seems like the application isn't recognizing the ALT key. Is that normal for windowed applications because of Alt-Tab or something?
Advertisement
In your WndProc function, you might be handling the WM_KEYDOWN message, but not handling WM_SYSKEYDOWN. The second one is what gets sent when the user is holding down Alt. (Docs).

The contents of the two messages are pretty much (maybe exactly?) the same, so in my switch block I just do this:

    case WM_KEYDOWN:    case WM_SYSKEYDOWN:        // etc.


Ditto for WM_SYSKEYUP.
if what pinacolada said does not work, then you may need to replace the call to TranslateMessage() in your main loop with something else. See the docs for that API. This is not trivial because the alt key is intended to be used in combination with other keys, which sounds like what you want anyway. In that case, why not create an accelerator table and only call TranslateMessage() when TranslateAccelerator() returns false like the docs say?
Quote:Original post by pinacolada
In your WndProc function, you might be handling the WM_KEYDOWN message, but not handling WM_SYSKEYDOWN.


Nice, it works now.

One question though: Is it possible to stop it from making that noise whenever Alt is used with another key? Is that something caused by being windowed perhaps?

This topic is closed to new replies.

Advertisement