如何禁用Alt键的正常行为?

时间:2021-07-17 20:01:01

Normally the Alt key opens the menu in Windows.

通常,Alt键会在Windows中打开菜单。

I need this to be disabled, because I need Alt key for my application. (It is an emulator of old computer, so I need to mimic its behaviour.) I write it in pure Windows API, so I expect there must be some message which is sent and needs to be disabled, discarded or ignored.

我需要禁用它,因为我的应用程序需要Alt键。 (它是旧计算机的模拟器,所以我需要模仿它的行为。)我在纯Windows API中编写它,所以我希望必须有一些消息发送,需要被禁用,丢弃或忽略。

Alt+Tab is no problem, as well as other system keys and key combinations, I just need to ignore Alt when it opens the menu.

Alt + Tab没有问题,以及其他系统键和组合键,我只需要在打开菜单时忽略Alt。

(My application uses DirectInput to read the keys, so it works well. I just need to disable the functionality which opens the menu with Alt key. I will open the menu using mouse.)

(我的应用程序使用DirectInput读取键,因此它运行良好。我只需要禁用使用Alt键打开菜单的功能。我将使用鼠标打开菜单。)

1 个解决方案

#1


12  

How about checking for WM_SYSCOMMAND, and when wParam is SC_KEYMENU, return 0?

如何检查WM_SYSCOMMAND,当wParam是SC_KEYMENU时,返回0?

Update / exact solution:

更新/确切解决方案:

if(wParam==SC_KEYMENU && (lParam>>16)<=0) return 0;
return DefWindowProc(hwnd, message, wParam, lParam);

Description: If lParam>>16 is positive then menu is activated by mouse, when it is zero or negative then menu is activated by Alt or Alt+something.

说明:如果lParam >> 16为正,则菜单由鼠标激活,当为零或为负时,菜单由Alt或Alt +激活。

#1


12  

How about checking for WM_SYSCOMMAND, and when wParam is SC_KEYMENU, return 0?

如何检查WM_SYSCOMMAND,当wParam是SC_KEYMENU时,返回0?

Update / exact solution:

更新/确切解决方案:

if(wParam==SC_KEYMENU && (lParam>>16)<=0) return 0;
return DefWindowProc(hwnd, message, wParam, lParam);

Description: If lParam>>16 is positive then menu is activated by mouse, when it is zero or negative then menu is activated by Alt or Alt+something.

说明:如果lParam >> 16为正,则菜单由鼠标激活,当为零或为负时,菜单由Alt或Alt +激活。