Original Post
I'm currently working on a project which involves making a wrapper for DirectInput. I've done so, but am having trouble getting the buffered input aspect of it working properly. Note that this is intended to be in a dll running in a game. I am attempting to inject input directly into this game from the dll. Can somebody please assist me? Thanks. Here are parts of the code: This class inherits from another, empty, wrapper. class KeyboardWrapper : public DirectInputDevice8AWrapper { public: KeyboardWrapper(IDirectInputDevice8A *pDirectInputDevice8A, DWORD CoopLevel); //virtual ~KeyboardWrapper(void); STDMETHOD(GetDeviceData)(THIS_ DWORD,LPDIDEVICEOBJECTDATA,LPDWORD,DWORD); STDMETHOD(GetDeviceState)(THIS_ DWORD,LPVOID); STDMETHOD(SetCooperativeLevel)(THIS_ HWND,DWORD); void SetKey(BYTE key, bool down); void SetKeyState(BYTE key, bool down); void InjectData(DIDEVICEOBJECTDATA data); void SetBlockInput(bool block); bool BlockInput; BYTE KeyState[256]; HWND Parent; DWORD Sequence; }; The following is from the KeyboardWRapper.cpp file: std::queue InjectedData; void KeyboardWrapper::SetKey(BYTE key, bool down) { InjectData(CreateKeyboardData(key, down)); SetKeyState(key, down); } void KeyboardWrapper::SetKeyState(BYTE key, bool down) { if(down) this->KeyState[key] = 0x80; else this->KeyState[key] = 0x00; } HRESULT KeyboardWrapper::GetDeviceData(THIS_ DWORD dword1, LPDIDEVICEOBJECTDATA lpdideviceobjectdata, LPDWORD lpdword, DWORD dword2) { //InjectData(CreateKeyboardData(DIK_A, true)); //InjectData(CreateKeyboardData(DIK_A, false)); //OutputDebugString("Keyboard - GetDeviceData"); bool block = false; if(GetForegroundWindowNext() != Parent || this->BlockInput) { block = true; } if(debugged == true) { } DWORD max = *lpdword; HRESULT result = this->DirectInputDevice8A->GetDeviceData(dword1, lpdideviceobjectdata, lpdword, dword2); if(*lpdword > 0) { if(lpdideviceobjectdata != NULL) { this->Sequence = lpdideviceobjectdata[*lpdword].dwSequence + 1; } } if(block) { *lpdword = 0; } else { *lpdword++; } if(lpdideviceobjectdata == NULL) return result; while(*lpdword < max && !InjectedData.empty()) { lpdideviceobjectdata[*lpdword] = InjectedData.back(); InjectedData.pop(); lpdideviceobjectdata[*lpdword].dwSequence = this->Sequence; this->Sequence++; *lpdword++; } return result; }