Original Post
Right now my input class looks roughly like this: SetKeyDown() and SetKeyUp() interface with the WndProc messages WM_KEYDOWN and WM_KEYUP. I tried having SetKeyDown/Up interface directly with m_keyState but got issues with buffered input due to the fact that WM_KEYDOWN/UP can be caught pretty much any time. But I figured, atleast each state is 32 bytes each instead of 256 bytes (array of bools). I have made a WinMain.cpp that has WinMain, sets up the window (this is for a game), and sets up my own WndProc to handle window messages. In WinMain.cpp I just put code in the WM_KEYDOWN and WM_KEYUP messages to call SetKeyDown(wParam) or SetKeyUp(wParam), respectively. The Update function is very very simple...looks like so: It has some XInput stuff too but that's it for keyboard input. So now, finally, on to the questions about this. 1) Is there a way to make my class independent of WndProc. Meaning...can I have my module self contained and not need to reach out for help? 2) In debug, or other low FPS situations, the input is very very delayed. It almost feels as if the windows messages are queueing up and taking a while to dispatch. Is there a way around this? 3) Is the way I'm doing this a good way of going about it? Using the UCHAR[32] setup is very nice. The code for getting to the correct bit is very simple and easily done with bitwise operations. If this isn't the best way, what is? I'm trying to stay away from using DirectInput or SDL. Thanks so much gamedev!
class CInput
{
private:
// singleton junk
CInput();
CInput(const CInput&);
CInput & operator=(const CInput&);
static CInput * m_pSingleton;
// SetKeyUp and SetKeyDown interface with this
UCHAR m_keyPoll[32];
// this is what we use to get if a key is down or up
UCHAR m_keyState[32];
// used for buffered input, keyState gets set to this each Update()
UCHAR m_keyPrevState[32];
public:
// singleton access
static CInput * GetSingleton();
void SetKeyDown(UCHAR _vkCode);
void SetKeyUp(UCHAR _vkCode);
// this returns a bool for XInput
// otherwise it just swaps around the keyPoll, keyState, and keyPrevState
bool Update(void);
// returns true if (m_keyState & (1 << _vkCode))
bool GetKey(UCHAR _vkCode);
// returns true if (m_keyState & (1 << _vkCode))
// && !(m_keyPrevState & (1 << _vkCode))
bool GetBufferedKey(UCHAR _vkCode);
// used for keybinding purposes, works mostly like _getch()
UCHAR GetPressedKey(void);
memcpy(m_keyPrevState, m_keyState, 32);
memcpy(m_keyState, m_keyPoll, 32);