Hi there,
Thought I could help since I see some errors with your program.
First, you have to put the ZeroMemory() in Clear(), because memory (with MS runtime at least) is initialized with 0xCD. If m_keys is never updated, KeyDown() would always return true because (0xcdcdcdcd & 0x80) would be 0x80 and hence true.
The second problem is that you modified m_keys from char to int. This doesn''t look bad but it NEEDS to be a char for Update().
Within the Update() is a GetDeviceState() call. You pass the size of m_keys and its'' address. For a keyboard it is predefined to be an array of 256 bytes. If the size is other that 256 bytes (in your case it would be 1024 bytes), the call would fail and m_keys would not contain the state of the keys. (You can verify by seeing if Keyboard::Update() returns false). This would combine with the 1st problem and you probably can''t send any keystrokes to your window and have to forcibly kill it.
I suggest you make m_keys back to char and put ZeroMemory() back and make sure it''s sizeof(char). You can leave the const int for KeyDown() and KeyUp() if you want but you should put an assert that the key variable should be between 0-255 since the array is only 256 elements.
class CKeyboard{public: CKeyboard(LPDIRECTINPUT8 pDI, HWND hwnd); ~CKeyboard(); bool KeyDown(const int key) { assert( (key>=0) && (key<256) ); // NEW return (m_keys[key] & 0x80) ? true : false; } bool KeyUp(const int key) { assert( (key>=0) && (key<256) ); // NEW return (m_keys[key] & 0x80) ? false : true; } bool Update(); void Clear() { ZeroMemory(m_keys, 256 * sizeof(char)); } // CHANGED bool Acquire(); bool Unacquire();private: LPDIRECTINPUTDEVICE8 m_pDIDev; char m_keys[256]; // CHANGED};
Hope this helps.