Re: [AD] Alt+F4 under Windows (fix?)

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


> I noticed the Alt-F4 key combination wasn't seen by my program when run
> under Windows, and after digging in the sources I spotted that Alt-F4 (and
> a number of other Windows key combinations) are blocked/ignored in
> wkeybd.c.

Yes, purposely. Alt+F4 is reserved by the system under Windows so it must
not be passed to the Allegro keyboard handler.

> I expect Alt-F4 is blocked to prevent the application being closed, but it
> also prevents it being used by the application itself.

No, Alt+F4 is blocked so that you don't try to use it in your program
because it means something else under Windows.

> To stop a WM_CLOSE being generated by Windows you just need to stop the
> WM_SYSKEYDOWN (with wParam == F4) being passed through to the default
> window procedure. As it happens this is already done in the normal case,
> when there's no user-specified window procedure to call

Indeed, and it's a bug. We have to honor Alt+F4 under Windows because the
system menu (Alt+space) contains an entry whose shortcut is Alt+F4.

Here's the patch I commited:

+   /* ignore special Windows keys (alt+tab, alt+space, (ctrl|alt)+esc) */
+   if (((scancode == DIK_TAB) && (_key_shifts & KB_ALT_FLAG))
+       || ((scancode == DIK_SPACE) && (_key_shifts & KB_ALT_FLAG))
+       || ((scancode == DIK_ESCAPE) && (_key_shifts & (KB_CTRL_FLAG | KB_ALT_FLAG))))
+      return;
 
-   /* ignore special Windows keys (alt+tab, alt+space, (ctrl|alt)+esc, alt+F4) */
-   if ((pressed) && 
-       ((((scancode & 0x7f) == 0x0F) && (_key_shifts & KB_ALT_FLAG)) ||
-       (((scancode & 0x7f) == 0x01) && (_key_shifts & (KB_CTRL_FLAG | KB_ALT_FLAG))) ||
-       (((scancode & 0x7f) == 0x39) && (_key_shifts & KB_ALT_FLAG)) ||
-       (((scancode & 0x7f) == 0x3E) && (_key_shifts & KB_ALT_FLAG))))
+   /* alt+F4 triggers a WM_CLOSE under Windows */
+   if ((scancode == DIK_F4) && (_key_shifts & KB_ALT_FLAG)) {
+      if (pressed)
+         PostMessage(allegro_wnd, WM_CLOSE, 0, 0);
       return;
+   }

--
Eric Botcazou



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/