I simply cannot figure out what's wrong here.
The situation is, when I press the "d" key, the program closes. This is great. I want it to close when I press any of the wasd keys. But it doesn't close when I press "w", "a", or "s".
man.moving is an int.
int ReadKeyboard() {
BYTE buffer[256];
ZeroMemory(buffer,256);
HRESULT hr = keyboard->GetDeviceState(sizeof(buffer),buffer);
if (FAILED(hr)) {
if (hr == DIERR_NOTACQUIRED) return 0x13;
}
// important index
// 0x01 escape
// 0x11 w
// 0x1e a
// 0x1f s
// 0x20 d
// 0xc8 up
// 0xcb left
// 0xd0 down
// 0xcd right
if (buffer[0x11]) { // w
man.moving |= 0x01;
}
else {
man.moving &= 0x01;
}
if (buffer[0x1e]) { // a
man.moving |= 0x02;
}
else {
man.moving &= 0x02;
}
if (buffer[0x1f]) { // s
man.moving |= 0x04;
}
else {
man.moving &= 0x04;
}
if (buffer[0x20]) { // d
man.moving |= 0x08;
}
else {
man.moving &= 0x08;
}
return man.moving;
}
As you can see I want it to set/unset flags based on which keys are down.
If man.moving is true, the program exits. It only exits if I press d though.
in WinMain():
if (int errorc = ReadKeyboard()) return errorc;
...and I just realized my error handling wasn't releasing any memory, just rather abruptly exiting the program.