本文整理汇总了C++中IDirectInputDevice8类的典型用法代码示例。如果您正苦于以下问题:C++ IDirectInputDevice8类的具体用法?C++ IDirectInputDevice8怎么用?C++ IDirectInputDevice8使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IDirectInputDevice8类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: gamepadCallback
// Callback that lists all gamepads.
static BOOL CALLBACK gamepadCallback(LPCDIDEVICEINSTANCE device,
LPVOID userData)
{
Impl* pimpl = static_cast<Impl*>(userData);
IDirectInputDevice8* gamepad;
if (FAILED(pimpl->input->CreateDevice(device->guidInstance,
&gamepad, 0)))
{
return DIENUM_CONTINUE;
}
if (FAILED(gamepad->SetDataFormat(&c_dfDIJoystick)) ||
FAILED(gamepad->SetCooperativeLevel(pimpl->window,
DISCL_EXCLUSIVE | DISCL_FOREGROUND)) ||
FAILED(gamepad->EnumObjects(axisCallback, gamepad, DIDFT_AXIS)))
{
gamepad->Release();
return DIENUM_CONTINUE;
}
pimpl->gamepads.push_back(Win::shareComPtr(gamepad));
return DIENUM_CONTINUE;
}
示例2: EnumGamepadCallback
// enumerate the dinput devices
int __stdcall plDInputMgr::EnumGamepadCallback(const DIDEVICEINSTANCE* device, void* pRef)
{
HRESULT hr;
plDInput* pDI = (plDInput*)pRef;
IDirectInputDevice8* fStick = nil;
hr = pDI->fDInput->CreateDevice(device->guidInstance, &fStick, NULL);
if(!FAILED(hr))
{
pDI->fSticks.Append(new plDIDevice(fStick));
// the following code pertaining to the action map shouldn't be here.
// in fact this shouldn't work at all according to MS, but this is
// currently the only way this works. Whatever - the correct
// code is here and commented out in case this ever gets fixed by MS
// in a future release of dinput.
HRESULT hr = fStick->BuildActionMap(pDI->fActionFormat, NULL, NULL);
if (!FAILED(hr))
{
hr = fStick->SetActionMap( pDI->fActionFormat, NULL, NULL );
DIPROPDWORD dipW;
dipW.diph.dwSize = sizeof(DIPROPDWORD);
dipW.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dipW.diph.dwHow = DIPH_DEVICE;
dipW.diph.dwObj = 0;
dipW.dwData = 500; // 5% of axis range for deadzone
hr = fStick->SetProperty(DIPROP_DEADZONE , &dipW.diph);
}
return DIENUM_CONTINUE;
}
return DIENUM_STOP;
}
示例3: axisCallback
// Callback that adjusts all found axes to [-stickRange, +stickRange].
static BOOL CALLBACK axisCallback(LPCDIDEVICEOBJECTINSTANCE instance,
LPVOID userData)
{
IDirectInputDevice8* dev = static_cast<IDirectInputDevice8*>(userData);
DIPROPRANGE range;
range.diph.dwSize = sizeof(DIPROPRANGE);
range.diph.dwHeaderSize = sizeof(DIPROPHEADER);
range.diph.dwHow = DIPH_BYID;
range.diph.dwObj = instance->dwType;
range.lMin = -stickRange;
range.lMax = +stickRange;
dev->SetProperty(DIPROP_RANGE, &range.diph);
return DIENUM_CONTINUE;
}
示例4:
IDirectInputDevice8 *BaseInputDevice::create_device(IDirectInput8 *pDI, GUID guid)
{
IDirectInputDevice8 *device;
HRESULT hr;
hr = pDI->CreateDevice(guid, &device, NULL);
if(FAILED(hr)) return NULL;
hr = device->SetCooperativeLevel(Render::hWnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
if(FAILED(hr))
{
device->Release(); return NULL;
}
device->Acquire();
return device;
}
示例5: pimpl
Gosu::Input::Input(HWND window)
: pimpl(new Impl)
{
pimpl->window = window;
pimpl->mouseFactorX = pimpl->mouseFactorY = 1.0;
// Create the main input object (only necessary for setup).
IDirectInput8* inputRaw;
Impl::check("creating the main DirectInput object",
::DirectInput8Create(Win::instance(), DIRECTINPUT_VERSION,
IID_IDirectInput8, reinterpret_cast<void**>(&inputRaw), 0));
pimpl->input = Win::shareComPtr(inputRaw);
// Prepare property struct for setting the amount of data to buffer.
DIPROPDWORD bufferSize;
bufferSize.diph.dwSize = sizeof(DIPROPDWORD);
bufferSize.diph.dwHeaderSize = sizeof(DIPROPHEADER);
bufferSize.diph.dwHow = DIPH_DEVICE;
bufferSize.diph.dwObj = 0;
bufferSize.dwData = Impl::inputBufferSize;
// Set up the system keyboard.
IDirectInputDevice8* kbRaw;
Impl::check("creating the keyboard device object",
pimpl->input->CreateDevice(GUID_SysKeyboard, &kbRaw, 0));
pimpl->keyboard = Win::shareComPtr(kbRaw);
Impl::check("setting the keyboard's data format",
kbRaw->SetDataFormat(&c_dfDIKeyboard));
Impl::check("setting the keyboard's cooperative level",
kbRaw->SetCooperativeLevel(window,
DISCL_FOREGROUND | DISCL_NONEXCLUSIVE));
Impl::check("setting the keyboard's buffer size",
kbRaw->SetProperty(DIPROP_BUFFERSIZE, &bufferSize.diph));
kbRaw->Acquire();
// Set up the system mouse.
IDirectInputDevice8* mouseRaw;
Impl::check("creating the mouse device object",
pimpl->input->CreateDevice(GUID_SysMouse, &mouseRaw, 0));
pimpl->mouse = Win::shareComPtr(mouseRaw);
Impl::check("setting the mouse's data format",
mouseRaw->SetDataFormat(&c_dfDIMouse));
Impl::check("setting the mouse's cooperative level",
mouseRaw->SetCooperativeLevel(window,
DISCL_FOREGROUND | DISCL_NONEXCLUSIVE));
Impl::check("setting the mouse's buffer size",
mouseRaw->SetProperty(DIPROP_BUFFERSIZE, &bufferSize.diph));
mouseRaw->Acquire();
pimpl->swapMouse = ::GetSystemMetrics(SM_SWAPBUTTON) != 0;
// Set up all gamepads.
pimpl->input->EnumDevices(DI8DEVCLASS_GAMECTRL, Impl::gamepadCallback,
pimpl.get(), DIEDFL_ATTACHEDONLY);
// Get into a usable default state.
pimpl->mouseX = pimpl->mouseY = 0;
pimpl->updateMousePos();
buttons.assign(false);
}
示例6: GetDeviceData
//In morrowind this only got called for keyboards when typing into the console. Probably no point in overriding it
//And so it turns out that oblivion uses this whever it's in menumode instead of just consoles. Figures.
HRESULT _stdcall GetDeviceData(DWORD a,DIDEVICEOBJECTDATA* b,DWORD* c,DWORD d) {
if (bufferedPresses.empty())
return RealDevice->GetDeviceData(a,b,c,d);
if(!b) {
DWORD temp=*c;
HRESULT hr = RealDevice->GetDeviceData(a,b,c,d);
if(c) *c=min(bufferedPresses.size(),temp);
if(!(d|DIGDD_PEEK)) while(!bufferedPresses.empty()) bufferedPresses.pop();
return hr;
}
int count=0;
while (bufferedPresses.size()) {
//Stricktly speaking, should return a buffer overflow by here, but if you do it breaks?
//Presumably, if you could mash your keyboard fast enough, no keypresses would register...
if(count==*c) return DI_OK; //DI_BUFFEROVERFLOW;
//This will not work correctly if DIGDD_PEEK is specified. afaik, it's only ever used if b == NULL
*b=bufferedPresses.front();
bufferedPresses.pop();
b+=sizeof(void*);
count++;
}
if(count==*c) return DI_OK;
//Can probably just return DI_OK here, because afaik *c is only ever 1 unless oblivion is trying to empty the buffer
*c-=count;
HRESULT hr=RealDevice->GetDeviceData(a,b,c,d);
*c+=count;
return hr;
}
示例7: Release
ULONG _stdcall Release(void) {
if(--Refs==0) {
RealDevice->Release();
delete this;
return 0;
} else { return Refs; }
}
示例8: Unacquire
HRESULT _stdcall Unacquire(void) { return RealDevice->Unacquire(); }
示例9: SetProperty
HRESULT _stdcall SetProperty(REFGUID a,const DIPROPHEADER* b) { return RealDevice->SetProperty(a,b); }
示例10: Acquire
HRESULT _stdcall Acquire(void) { return RealDevice->Acquire(); }
示例11: Escape
HRESULT _stdcall Escape(LPDIEFFESCAPE a) { return RealDevice->Escape(a); }
示例12: GetProperty
HRESULT _stdcall GetProperty(REFGUID a,DIPROPHEADER* b) { return RealDevice->GetProperty(a,b); }
示例13: CreateEffect
HRESULT _stdcall CreateEffect(REFGUID a,LPCDIEFFECT b,LPDIRECTINPUTEFFECT *c,LPUNKNOWN d) { return RealDevice->CreateEffect(a,b,c,d); }
示例14: SendForceFeedbackCommand
HRESULT _stdcall SendForceFeedbackCommand(DWORD a) { return RealDevice->SendForceFeedbackCommand(a); }
示例15: QueryInterface
/*** IUnknown methods ***/
HRESULT _stdcall QueryInterface (REFIID riid, LPVOID * ppvObj) { return RealDevice->QueryInterface(riid,ppvObj); }