Any reason ALT might not work?

Recommended Posts

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?

Share on other sites
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.

Share on other sites
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?

Share on other sites
Quote:
 Original post by pinacoladaIn 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?

Create an account

Register a new account

• Forum Statistics

• Total Topics
628320
• Total Posts
2982057

• 12
• 9
• 9
• 13
• 11