[英]Remove Windows Error/Beep sound when pressing Alt + Key combinations
我正在尝试从我的 Flutter (Win32) 应用程序中删除 windows 错误声音。 经过一些研究,我想出了这个修复方法。 我尝试了此修复程序,但它对我的 Flutter 应用程序没有帮助。
下面是处理WM_SYSCHAR
消息的代码:
LRESULT CALLBACK Win32Window::WndProc(HWND const window,
UINT const message,
WPARAM const wparam,
LPARAM const lparam) noexcept {
if (message == WM_SYSCHAR) {
std::cout << "SYSCHAR from win32" << std::endl;
return 0;
}
...
}
当我按下 Alt+Space 时,“SYSCHAR from win32”会打印在控制台中。 但是每当我用 Alt 按下任何其他键时,都不会打印出来,并且会播放 Windows 错误声音。 似乎SYSCHAR
消息在其他地方处理?
这可以用来了解Flutter中Win32 App的工作和初始化。
我只想告诉应用程序已处理 Alt+Key 组合,它不必播放 Windows 错误声音。
感谢@IInspectable建议我使用键盘加速器。
问题是 Flutter 的主循环没有键盘加速器。 所以我按照how to use keyboard accelerts 文档修改了主循环如下:
LPACCEL accels = GenerateAccels();
HACCEL haccel = CreateAcceleratorTable(accels, 36);
if (haccel==NULL) {
return EXIT_FAILURE;
}
这是GenerateAccels
function:
LPACCEL GenerateAccels() {
LPACCEL lpAccel = new ACCEL[36];
// Alt + Number combinations:
for (int i = 0; i < 10; i++) {
lpAccel[i].fVirt = FALT;
lpAccel[i].key = (WORD)(0x30 + i);
}
// Alt + Alphabet combinations (NOT WORKING AT THE MOMENT):
for (int i = 0; i < 26; i++) {
lpAccel[i + 10].fVirt = FALT;
lpAccel[i + 10].key = (WORD)(0x41 + i);
}
return lpAccel;
}
::MSG msg = { };
while (::GetMessage(&msg, nullptr, 0, 0) > 0) {
if (!TranslateAccelerator(msg.hwnd, haccel, &msg)) {
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
}
flutter_window.cpp
case WM_SYSCOMMAND: // If the selection is in menu // handle the key event // This prevents the error/beep sound if (wparam == SC_KEYMENU) { return 0; }
注意:一件事不起作用是Alt + 字母组合。 按下时,它仍在播放错误声音。 就我而言,现在这并不重要,但如果有人找到了解决方法,请分享。
问题未解决?试试以下方法:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.