Original Post
I'm having trouble with direct input. I am using direct input in immediate mode and am wanting to use to control game state changes, eg pause. The key to pause and unpause is the same and the problem i'm having is that the key is registered more than once in a single key press. I'm using the GetDeviceState() function every frame so I understand why this is happening. In order try fix this I simply held the last state of the each key. When A key is queried I only return true if the the key is pressed and was not pressed in the previous frame. This doesn't seem to be working however. This is the class i'm using to represent a single key. GetNewPress() is the function i'm wanting to use for state changes. This however doesn't work and i'm not sure how. Can anyone see anything wrong with my code? Or could it be how I set up direct input?
class CActionState
{
public:
CActionState() : _state(false), _lastState(false) {}
void SetState(bool newState)
{
_lastState = _state;
_state = newState;
}
bool GetState() const {return _state;}
bool GetNewPress() const {return _state && !_lastState;}
private:
bool _state;
bool _lastState;
};