Simulate piano pressed keys

I need to simulate pressed piano keys with my keyboard, but I can't get it to work. I can get sounds to play when I create the window(execute my code), but not when I press any keys. These sounds play automatically if I put them before the switch(message). Nothing happens when I press the keys, have I missed something obvious?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HMIDIOUT hMidiOut;
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;

// Open MIDI for output 
midiOutOpen(&hMidiOut, -1, 0, 0, 0); 
// Set instrument to 0 = Acoustic Grand Piano 
midiOutShortMsg(hMidiOut, DWORD(0x0C0 | 0 | (0 << 8) | (0 << 16))); 


switch (message)
{
case WM_KEYDOWN:
{
switch (wParam) {

case VK_LEFT:

    // Set instrument to 0 = Acoustic Grand Piano

    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;
}
Topic archived. No new replies allowed.