C++ Win32 - 响应按键
C++ Win32- Responding to Key Presses
我正在尝试制作我模拟的 win32 应用程序,我按下钢琴上的 C
键,键盘编号 60,并使用以下调用:midiOutShortMsg (hMidiOut, DWORD (0x090 | 0 | (60 << 8) | (64 << 16)));
释放 60 号键时,请按以下调用:midiOutShortMsg (hMidiOut, DWORD (0x080 | 0 | (60 << 8) | (0 << 16)));
问题是,当我按下按钮时,我只听到一次声音。 当我运行程序时,只有一个案例有效。
我怎么能做到只要我按下声音就会重复。 以及如何做一个长旋律播放。
case WM_KEYDOWN:
{
switch (wParam) {
case VK_LEFT:
midiOutOpen(&hMidiOut, -1, 0, 0, 0);
// Set instrument to 0 = Acoustic Grand Piano
midiOutShortMsg(hMidiOut, DWORD(0x0C0 | 0 | (0 << 8) | (0 << 16)));
midiOutShortMsg (hMidiOut, DWORD(0x090 | 0 | (65<<8 ) | (64 << 16)));
break;
case 'S':
midiOutShortMsg (hMidiOut, DWORD(0x090 | 0 | (62<<8 ) | (64 << 16)));
break;
case 'D':
midiOutShortMsg (hMidiOut, DWORD(0x090 | 0 | (64<<8 ) | (64 << 16)));
break;
case 'F':
midiOutShortMsg (hMidiOut, DWORD(0x090 | 0 | (65<<8 ) | (64 << 16)));
break;
case 'G':
midiOutShortMsg (hMidiOut, DWORD(0x090 | 0 | (67<<8 ) | (64 << 16)));
break;
case 'H':
midiOutShortMsg (hMidiOut, DWORD(0x090 | 0 | (69<<8 ) | (64 << 16)));
break;
case 'J':
midiOutShortMsg (hMidiOut, DWORD(0x090 | 0 | (71<<8 ) | (64 << 16)));
break;
case 'K':
midiOutShortMsg (hMidiOut, DWORD(0x090 | 0 | (72<<8 ) | (64 << 16)));
break;
我想你可以存储键状态(也许使用布尔数组)并在消息处理循环中进行播放。
相关文章:
- Win32编译器选项和内存分配
- C++win32 API创建多个类似视口的窗口
- WM_CTLCOLORSTATIC从未在WIN32应用程序中触发
- 检测win32服务创建和删除的最佳方法
- WIN32:C++,为什么在WM_CLOSE上调用Messagebox函数程序正在冻结
- 当服务中的事件被触发时,如何将响应从服务发送回客户端?
- 将 win32 hbitmap 转换为 winrt softwarebitmap
- 使用 WIN32 API (C/C++) 对特定树视图项进行着色
- Alt+Enter 在 Win32 应用中,管理大小调整和分辨率
- VSCode C++ 编译的exe感染了Win32:TrojanX-gen[Trj]
- 从预处理器获取 Windows 版本(C++ Win32)
- Issues with Win32 ReadProcessMemory API
- Win32 发送输入鼠标移动滞后并冻结
- 如何从 Win32 C++ 应用程序输出到父控制台窗口?
- C++线程:如何在一个线程仍在运行时阻止另一个线程执行 (Win32)
- C++ 信号和插槽不工作:插槽不响应事件
- 将 Win32/WinAPI 应用程序移植到 wxWidgets
- Win32 中的 Sleep() 使程序无响应
- C++ Win32 - 响应按键
- C++ WIN32 WM_KEYDOWN没有响应