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 | // ...
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
case WM_KEYDOWN:
case WM_KEYUP:
{
// 24th bit is extended keys, numpad, right alt & ctrl
// 29th bit is context code - alt key down
// 30th bit is Previous key state - reapeated keydown is 1
// 31st bit is Transistion state - 0 for down
uint32 VKCode = (uint32)Message.wParam;
bool32 WasDown = ((Message.lParam & (1 << 30)) != 0);
bool32 IsDown = ((Message.lParam & (1 << 31)) == 0);
// Ignore duplicate input
if (WasDown != IsDown)
{
//Win32AssignKeyboard(keyboard, VKCode, IsDown);
if (VKCode == 'W')
{
Win32ProcessKeyboardMessage(&keyboard->MoveUp, IsDown);
OutputDebugStringA("KEYDOWN\n");
} else if (VKCode == 'A')
{
Win32ProcessKeyboardMessage(&keyboard->MoveLeft, IsDown);
} else if (VKCode == 'S')
{
Win32ProcessKeyboardMessage(&keyboard->MoveDown, IsDown);
} else if (VKCode == 'D')
{
Win32ProcessKeyboardMessage(&keyboard->MoveRight, IsDown);
}
}
// ...
|
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 | // ...
game_input Input[2] = {};
game_input *NewInput = &Input[0];
game_input *OldInput = &Input[1];
// ...
while (Running)
{
// I've copied Caseys code here and it produces the same error with Old/NewKeyboardController
game_controller *Keyboard = &NewInput->Controllers[0];
*Keyboard = {};
Keyboard->IsConnected = true;
for (int KeyIndex = 0;
KeyIndex < ArrayCount(Keyboard->Buttons);
++KeyIndex)
{
Keyboard->Buttons[KeyIndex].IsDown =
OldInput->Controllers[0].Buttons[KeyIndex].IsDown;
}
Win32ProcessPendingMessages(Keyboard);
// ...
game_input *Temp = NewInput;
NewInput = OldInput;
OldInput = Temp;
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | internal void
Win32ProcessKeyboardMessage(game_button_state *NewState, bool32 IsDown)
{
If (NewState->IsDown)
OutputDebugStringA("1, ");
else
OutputDebugStringA("0, ");
If (IsDown)
OutputDebugStringA("1\n");
else
OutputDebugStringA("0\n");
Assert(NewState->IsDown != IsDown);
NewState->IsDown = IsDown;
++NewState->HalfTransitionCount;
}
|
1 2 3 4 5 6 7 | /* Just after Win32ProcessPendingMessages */ b32 is_pressed = Keyboard->MoveUp.IsDown; /* Game code here */ /* Just before swapping NewInput and OldInput */ Assert( is_pressed == Keyboard->MoveUp.IsDown ); |