bool DirectInput_Init(HWND hwnd) { //initialize DirectInput object DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&dinput, NULL); //initialize the keyboard dinput->CreateDevice(GUID_SysKeyboard, &dikeyboard, NULL); dikeyboard->SetDataFormat(&c_dfDIKeyboard); dikeyboard->SetCooperativeLevel(hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND); dikeyboard->Acquire(); //initialize the mouse dinput->CreateDevice(GUID_SysMouse, &dimouse, NULL); dimouse->SetDataFormat(&c_dfDIMouse); dimouse->SetCooperativeLevel(hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND); dimouse->Acquire(); d3ddev->ShowCursor(false); return true; }
bool initDIDevice(HINSTANCE hInstance, HWND hWnd) { // Initialisation de DirectInput if(FAILED(DirectInput8Create(hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void **)&g_pDI, NULL))) return false; // Initialisation du clavier if(FAILED(g_pDI->CreateDevice(GUID_SysKeyboard, &g_pKeyboardDevice, NULL))) return false; if(FAILED(g_pKeyboardDevice->SetDataFormat(&c_dfDIKeyboard))) return false; if(FAILED(g_pKeyboardDevice->SetCooperativeLevel(hWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE))) return false; if(FAILED(g_pKeyboardDevice->Acquire())) return false; // Initialisation de la souris if(FAILED(g_pDI->CreateDevice(GUID_SysMouse, &g_pMouseDevice, NULL))) return false; if(FAILED(g_pMouseDevice->SetDataFormat(&c_dfDIMouse))) return false; if(FAILED(g_pMouseDevice->SetCooperativeLevel(hWnd, DISCL_FOREGROUND | DISCL_EXCLUSIVE))) return false; if(FAILED(g_pMouseDevice->Acquire())) return false; return true; }
int GutInputInit(void) { memset(g_pKeyDownFuncs, 0, sizeof(g_pKeyDownFuncs)); memset(g_pKeyUpFuncs, 0, sizeof(g_pKeyUpFuncs)); memset(g_pKeyPressedFuncs, 0, sizeof(g_pKeyPressedFuncs)); int hr; HWND hwnd = GutGetWindowHandleWin32(); HINSTANCE hinst = GutGetWindowInstanceWin32(); hr = DirectInput8Create( hinst, DIRECTINPUT_VERSION, IID_IDirectInput8, (void **)&g_pDI, NULL); if ( FAILED(hr) ) return 0; // create keyboard device hr = g_pDI->CreateDevice( GUID_SysKeyboard, &g_pKeyboard, NULL ); if ( FAILED(hr) ) return 0; if ( g_pKeyboard ) { g_pKeyboard->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE ); g_pKeyboard->SetDataFormat(&c_dfDIKeyboard); g_pKeyboard->Acquire(); } // create mouse device hr = g_pDI->CreateDevice(GUID_SysMouse, &g_pMouse, NULL); if ( FAILED(hr) ) return 0; if ( g_pMouse ) { g_pMouse->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE ); g_pMouse->SetDataFormat(&c_dfDIMouse2); g_pMouse->Acquire(); } GetCursorPos(&g_op); ScreenToClient(hwnd, &g_op); g_mouse = g_op; // create joystick device hr = g_pDI->EnumDevices(DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, NULL, DIEDFL_ATTACHEDONLY); if ( FAILED(hr) ) return 0; if ( g_pJoystick ) { g_pJoystick->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE ); g_pJoystick->SetDataFormat(&c_dfDIJoystick); g_pJoystick->Acquire(); } return 1; }
//============================================================================= // キーボードの初期化 //============================================================================= HRESULT InitKeyboard(HINSTANCE hInst, HWND hWnd) { HRESULT hr; // デバイスオブジェクトを作成 hr = g_pDInput->CreateDevice(GUID_SysKeyboard, &g_pDIDevKeyboard, NULL); if(FAILED(hr) || g_pDIDevKeyboard == NULL) { MessageBox(hWnd, "キーボードがねぇ!", "警告!", MB_ICONWARNING); return hr; } // データフォーマットを設定 hr = g_pDIDevKeyboard->SetDataFormat(&c_dfDIKeyboard); if(FAILED(hr)) { MessageBox(hWnd, "キーボードのデータフォーマットを設定できませんでした。", "警告!", MB_ICONWARNING); return hr; } // 協調モードを設定(フォアグラウンド&非排他モード) hr = g_pDIDevKeyboard->SetCooperativeLevel(hWnd, (DISCL_FOREGROUND | DISCL_NONEXCLUSIVE)); if(FAILED(hr)) { MessageBox(hWnd, "キーボードの協調モードを設定できませんでした。", "警告!", MB_ICONWARNING); return hr; } // キーボードへのアクセス権を獲得(入力制御開始) g_pDIDevKeyboard->Acquire(); return S_OK; }
BOOL KeyboardInit (HWND hWindow, int iMin, int iMax, int iDeadZone) { if (FAILED(m_lpkDI->CreateDevice ( pdidInstance->guidInstance, m_lpkDKB, NULL)) ) { return DIENUM_CONTINUE; } else { return DIENUM_STOP; } if (FAILED(m_lpkDKB->SetDataFormat (&c_dfDIKeyboard))) { return FALSE; } /* Acquire joystick */ HRESULT hRet = m_lpkDKB->Poll (); if (FAILED (hRet)) { hRet = m_lpkDKB->Acquire (); while (hRet == DIERR_INPUTLOST) { hRet = m_lpkDKB->Acquire (); } } return TRUE; }
///////////////////////////////////// // Name: INPMouseInit // Purpose: initialize mouse // if bExclusive, this means // we don't get actual windows // mouse location. Use it on // fullscreen only. // Output: mouse initialized // Return: success if so ///////////////////////////////////// s32 F_API INPMouseInit(void *hMain, u8 bExclusive, iPoint *pBound) { INPMouseDestroy(); HRESULT hr; //create the mouse device hr = g_pDInput->CreateDevice(GUID_SysMouse, &g_pDMouse, NULL); if(FAILED(hr)) { DInputError(hr, L"INPMouseInit"); return RETCODE_FAILURE; } //set mouse device as a REAL mouse hr = g_pDMouse->SetDataFormat(&c_dfDIMouse2); if(FAILED(hr)) { DInputError(hr, L"INPMouseInit"); return RETCODE_FAILURE; } //set up mouse coop level u32 coop = g_coopFlag & ~(INP_EXCLUSIVE | INP_NONEXCLUSIVE); coop |= bExclusive ? INP_EXCLUSIVE : INP_NONEXCLUSIVE; hr = g_pDMouse->SetCooperativeLevel((HWND)hMain, coop); if(FAILED(hr)) { DInputError(hr, L"INPMouseInit"); return RETCODE_FAILURE; } //acquire mouse device g_pDMouse->Acquire(); g_bExclusive = bExclusive; memset(&g_mouseLoc, 0, sizeof(g_mouseLoc)); INPMouseSetBound(pBound); return RETCODE_SUCCESS; }
//DirectInputデバイスの初期化 bool Application::InitDinputDevice() { //DirectInputデバイスを作成 if (FAILED(directInput->CreateDevice(GUID_SysMouse, &dinputDevice, nullptr))) return false; //データフォーマットを設定 if (FAILED(dinputDevice->SetDataFormat(&c_dfDIMouse2))) return false; //協調モードを設定 if (FAILED(dinputDevice->SetCooperativeLevel(hWnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND))) return false; // 軸モードを設定 DIPROPDWORD diprop; diprop.diph.dwSize = sizeof(diprop); diprop.diph.dwHeaderSize = sizeof(diprop.diph); diprop.diph.dwObj = 0; diprop.diph.dwHow = DIPH_DEVICE; diprop.dwData = DIPROPAXISMODE_REL; if (FAILED(dinputDevice->SetProperty(DIPROP_AXISMODE, &diprop.diph))) { MessageBox(NULL, "設定に失敗", "Direct Input Error", MB_OK); return false; } // 入力制御開始 dinputDevice->Acquire(); return true; }
int DInput_Init_Keyboard(void) { // this function initializes the keyboard device // create the keyboard device if (lpdi->CreateDevice(GUID_SysKeyboard, &lpdikey, NULL)!=DI_OK) return(0); // set cooperation level if (lpdikey->SetCooperativeLevel(main_window_handle, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND)!=DI_OK) return(0); // set data format if (lpdikey->SetDataFormat(&c_dfDIKeyboard)!=DI_OK) return(0); // acquire the keyboard if (lpdikey->Acquire()!=DI_OK) return(0); // return success return(1); } // end DInput_Init_Keyboard
//----------------------------------------------------------------------------- // Name: InitDirectInput() // Desc: Initialize the DirectInput variables. //----------------------------------------------------------------------------- HRESULT InitDirectInput( HWND hDlg ) { HRESULT hr; // Register with the DirectInput subsystem and get a pointer // to a IDirectInput interface we can use. if( FAILED( hr = DirectInput8Create( GetModuleHandle( NULL ), DIRECTINPUT_VERSION, IID_IDirectInput8, ( VOID** )&g_pDI, NULL ) ) ) return hr; // Retrieve the system mouse if( FAILED( g_pDI->CreateDevice( GUID_SysMouse, &g_pMouse, NULL ) ) ) { MessageBox( NULL, TEXT( "Mouse not found. The sample will now exit." ), TEXT( "DirectInput Sample" ), MB_ICONERROR | MB_OK ); EndDialog( hDlg, 0 ); return S_OK; } // A data format specifies which controls on a device we are interested in, // and how they should be reported. This tells DInput that we will be // passing a MouseState structure to IDirectInputDevice::GetDeviceState(). if( FAILED( hr = g_pMouse->SetDataFormat( &g_dfMouse ) ) ) return hr; // Set the cooperative level to let DInput know how this device should // interact with the system and with other DInput applications. if( FAILED( hr = g_pMouse->SetCooperativeLevel( hDlg, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND ) ) ) return hr; return S_OK; }
int DInput_Init_Mouse(void) { // this function intializes the mouse // create a mouse device if (lpdi->CreateDevice(GUID_SysMouse, &lpdimouse, NULL)!=DI_OK) return(0); // set cooperation level // change to EXCLUSIVE FORGROUND for better control if (lpdimouse->SetCooperativeLevel(main_window_handle, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND)!=DI_OK) return(0); // set data format if (lpdimouse->SetDataFormat(&c_dfDIMouse)!=DI_OK) return(0); // acquire the mouse if (lpdimouse->Acquire()!=DI_OK) return(0); // return success return(1); } // end DInput_Init_Mouse
//------------------------------------------------------ // コントローラー初期化 //------------------------------------------------------ LPDIRECTINPUTDEVICE8 iexInputManager::GetDevice( int n ) { HRESULT hr; LPDIRECTINPUTDEVICE8 lpDevice; // デバイス生成 hr = pDI->CreateDevice( didi[n].guidInstance, &lpDevice, NULL); if( FAILED(hr) ) return NULL; if( lpDevice->SetDataFormat( &c_dfDIJoystick2 ) != DI_OK ) return FALSE; if( lpDevice->SetCooperativeLevel( iexSystem::Window, DISCL_EXCLUSIVE | DISCL_FOREGROUND ) != DI_OK ) return FALSE; // 自動センタリング無効 DIPROPDWORD dipdw; dipdw.diph.dwSize = sizeof(DIPROPDWORD); dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); dipdw.diph.dwObj = 0; dipdw.diph.dwHow = DIPH_DEVICE; dipdw.dwData = DIPROPAUTOCENTER_OFF; lpDevice->SetProperty( DIPROP_AUTOCENTER, &dipdw.diph ); // 各軸設定 lpDevice->EnumObjects(EnumAxes, lpDevice, DIDFT_AXIS); // 入力制御開始 lpDevice->Acquire(); return lpDevice; }
BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance, VOID* pContext ) { LPDIRECTINPUTDEVICE8 dinJoystick; // Obtain an interface to the enumerated joystick. HRESULT hr = din->CreateDevice( pdidInstance->guidInstance, &dinJoystick, NULL ); if ( FAILED( hr ) ) return ( DIENUM_CONTINUE ); dinJoystick->SetDataFormat( &c_dfDIJoystick2 ); HWND hWnd = *( (HWND*)pContext ); dinJoystick->SetCooperativeLevel( hWnd, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND ); unsigned char i = numJoysticks++; dinJoysticks[i] = dinJoystick; unsigned int nameLength = strlenW( pdidInstance->tszInstanceName ); char* name = (char*)malloc( nameLength + 1 ); //memcpy( name, pdidInstance->tszInstanceName, nameLength + 1 ); copyWideStringToString( pdidInstance->tszInstanceName, name ); joystickNames[i] = name; numButtons[i] = 0; buttonNames[i] = (char**)malloc( 256 ); dinJoystick->EnumObjects( &EnumButtonsCallback, &i, DIDFT_BUTTON ); //return ( DIENUM_STOP ); return ( DIENUM_CONTINUE ); }
C_RESULT open_dx_keyboard(void) { HRESULT hr; HWND hDlg = GetConsoleHwnd(); // Register with the DirectInput subsystem and get a pointer // to a IDirectInput interface we can use. // Create a DInput object if (g_pDI==NULL) if( VP_FAILED( hr = DirectInput8Create( GetModuleHandle( NULL ), DIRECTINPUT_VERSION, IID_IDirectInput8, ( VOID** )&g_pDI, NULL ) ) ) return hr; // Create the connection to the keyboard device g_pDI->CreateDevice(GUID_SysKeyboard, &fDIKeyboard, NULL); if (fDIKeyboard) { fDIKeyboard->SetDataFormat(&c_dfDIKeyboard); fDIKeyboard->SetCooperativeLevel(hDlg,DISCL_FOREGROUND | DISCL_EXCLUSIVE); fDIKeyboard->Acquire(); } return C_OK; }
/// a function that Initializes all direct input stuff void TSRInputSubSystem::Init() { #if defined( WIN32 ) || defined( WIN64 ) if ( FAILED( DirectInput8Create( GetModuleHandle( 0 ), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&m_lpdi, NULL) ) ) { TSRFatalError( "Error Creating main direct input object" ); } if ( FAILED( m_lpdi->CreateDevice( GUID_SysMouse, &m_lpdimouse, NULL ) ) ) { TSRFatalError( "Error Creating mouse device" ); } if ( FAILED( m_lpdimouse->SetCooperativeLevel( NULL, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE ) ) ) { TSRFatalError( "Error Setting mouse cooperative level" ); } if ( FAILED( m_lpdimouse->SetDataFormat( &c_dfDIMouse ) ) ) { TSRFatalError( "Error setting mouse data fromat" ); } if ( FAILED ( m_lpdimouse->Acquire() ) ) { TSRFatalError( "error aquiring mouse" ); } #endif }
// Called for every enumerated DI device (only vJoy device supported) // Create a DI device and enumerate the device object - this is to obtain the device ID // Convert this ID to Unique ID and get the corresponding entry in DB or create one // - If exists then mark as 'exist' and update DI device BOOL CvJoyMonitor::EnumJoysticks(const DIDEVICEINSTANCE* pdidInstance) { HRESULT hr; LPDIRECTINPUTDEVICE8 pJoystick; // If not vJoy device then ignore if (((pdidInstance)->guidProduct).Data1 != PID2) return TRUE; // This is a vJoy device - Create a DI device hr = m_pDI->CreateDevice( pdidInstance->guidInstance, &pJoystick, NULL ); // If it failed, then we can't use this Joystick. (Maybe the user unplugged // it while we were in the middle of enumerating it.) if( FAILED( hr ) ) return DIENUM_CONTINUE; // Set the data format to "simple Joystick" - a predefined data format // // A data format specifies which controls on a device we are interested in, // and how they should be reported. This tells DInput that we will be // passing a DIJOYSTATE2 structure to IDirectInputDevice::GetDeviceState(). if( FAILED(pJoystick->SetDataFormat( &c_dfDIJoystick2 ))) return TRUE; // Get device objects and ID m_CurrentID=0; if( FAILED(pJoystick->EnumObjects( _EnumObjects, ( VOID* )this, DIDFT_AXIS|DIDFT_BUTTON|DIDFT_POV ) ) ) return TRUE; // Convert vJoy ID to Unique ID wstring UniqueID = Convert2UniqueID(m_CurrentID); // Find device in DB by unique ID // If found - Update its data mapDB::iterator iMap; iMap = m_DeviceDB.find(UniqueID); if( iMap != m_DeviceDB.end() ) { // Found (*iMap).second->Exist=true; SAFE_RELEASE((*iMap).second->pDeviceDI8); (*iMap).second->pDeviceDI8=pJoystick; } else { // Not found - Create Device * dev = new Device(); dev->UniqueID=UniqueID; dev->Exist=true; dev->pDeviceDI8=pJoystick; dev->isvJoyDevice=true; dev->RqPolling=false; dev->ThPolling=NULL; dev->isPolling=false; dev->vJoyID = m_CurrentID; m_DeviceDB.emplace(UniqueID,dev); }; return TRUE; }
//----------------------------------------------------------------------------- // Name: InitDirectInput() // Desc: Initialize the DirectInput variables. //----------------------------------------------------------------------------- HRESULT InitDirectInput( HWND hWnd ) { HRESULT hr; // Register with the DirectInput subsystem and get a pointer // to a IDirectInput interface we can use. // Create a DInput object if( FAILED( hr = DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&g_pDI, NULL ) ) ) return hr; // Obtain an interface to the system mouse device. if( FAILED( hr = g_pDI->CreateDevice( GUID_SysMouse, &g_pMouse, NULL ) ) ) return hr; // Set the data format to "mouse format" - a predefined data format // // A data format specifies which controls on a device we // are interested in, and how they should be reported. // // This tells DirectInput that we will be passing a // DIMOUSESTATE structure to IDirectInputDevice::GetDeviceState. if( FAILED( hr = g_pMouse->SetDataFormat( &c_dfDIMouse ) ) ) return hr; // Set the cooperativity level to let DirectInput know how // this device should interact with the system and with other // DirectInput applications. if( FAILED( hr = g_pMouse->SetCooperativeLevel( hWnd, DISCL_EXCLUSIVE|DISCL_FOREGROUND ) ) ) return hr; // Create a win32 event which is signaled when mouse data is availible g_hMouseEvent = CreateEvent( NULL, FALSE, FALSE, NULL ); if( NULL == g_hMouseEvent ) return E_FAIL; // Give the event to the mouse device if( FAILED( hr = g_pMouse->SetEventNotification( g_hMouseEvent ) ) ) return hr; // Setup the buffer size for the mouse data DIPROPDWORD dipdw; dipdw.diph.dwSize = sizeof(DIPROPDWORD); dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); dipdw.diph.dwObj = 0; dipdw.diph.dwHow = DIPH_DEVICE; dipdw.dwData = SAMPLE_BUFFER_SIZE; // Arbitary buffer size if( FAILED( hr = g_pMouse->SetProperty( DIPROP_BUFFERSIZE, &dipdw.diph ) ) ) return hr; // Not necessary, but nice for left handed users that have // their swapped mouse buttons g_bSwapMouseButtons = GetSystemMetrics( SM_SWAPBUTTON ); return S_OK; }
static int Mouse_Win32_Init() { if(CommandLine_Check("-nomouse") || novideo) return false; // We'll need a window handle for this. HWND hWnd = (HWND) ClientWindow::main().nativeHandle(); HRESULT hr = E_FAIL; // Prefer the newer version 8 interface if available. if(LPDIRECTINPUT8 dInput = DirectInput_IVersion8()) { hr = dInput->CreateDevice(GUID_SysMouse, &didMouse, 0); } else if(LPDIRECTINPUT dInput = DirectInput_IVersion3()) { hr = dInput->CreateDevice(GUID_SysMouse, (LPDIRECTINPUTDEVICE*) &didMouse, 0); } if(FAILED(hr)) { LOGDEV_INPUT_ERROR("Failed to create device (0x%x: %s)") << hr << DirectInput_ErrorMsg(hr); return false; } // Set data format. hr = didMouse->SetDataFormat(&c_dfDIMouse2); if(FAILED(hr)) { LOGDEV_INPUT_ERROR("Failed to set data format (0x%x: %s)") << hr << DirectInput_ErrorMsg(hr); goto kill_mouse; } // Set behavior. hr = didMouse->SetCooperativeLevel(hWnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND); if(FAILED(hr)) { LOGDEV_INPUT_ERROR("Failed to set co-op level (0x%x: %s)") << hr << DirectInput_ErrorMsg(hr); goto kill_mouse; } // Acquire the device. //didMouse->Acquire(); //mouseTrapped = true; // We will be told when to trap the mouse. mouseTrapped = false; // Init was successful. return true; kill_mouse: I_SAFE_RELEASE(didMouse); return false; }
int Init_Mouse(HWND hwnd) { HRESULT result = dimouse->SetDataFormat(&c_dfDIMouse); result = dimouse->SetCooperativeLevel(hwnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND); result = dimouse->Acquire(); return 1; }
void initialize(HWND hwnd) { DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&directInput, NULL); directInput->CreateDevice(GUID_SysMouse, &mouseDevice, 0); mouseDevice->SetDataFormat(&c_dfDIMouse); mouseDevice->SetCooperativeLevel(hwnd, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE ); mouseDevice->Acquire(); directInput->CreateDevice( GUID_SysKeyboard, &keyboardDevice, 0); keyboardDevice->SetDataFormat(&c_dfDIKeyboard); keyboardDevice->SetCooperativeLevel(hwnd, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE ); keyboardDevice->Acquire(); }
bool initDirect3D(HINSTANCE hInstance) { pD3D = NULL; pd3dDevice = NULL; bool result = false; if (NULL != (pD3D = Direct3DCreate9(D3D_SDK_VERSION))) { D3DPRESENT_PARAMETERS d3dpp; ZeroMemory(&d3dpp, sizeof(d3dpp)); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; d3dpp.BackBufferCount = 1; d3dpp.BackBufferHeight = windowHeight; d3dpp.BackBufferWidth = windowWidth; d3dpp.hDeviceWindow = hWin; d3dpp.EnableAutoDepthStencil = TRUE; d3dpp.AutoDepthStencilFormat = D3DFMT_D16; result = ! FAILED(pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWin, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pd3dDevice)); pd3dDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_TRUE ); // Create the DirectInput object. HRESULT hr = DirectInput8Create(hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&g_lpDI, NULL); if FAILED(hr) return FALSE; // Retrieve a pointer to an IDirectInputDevice8 interface hr = g_lpDI->CreateDevice(GUID_SysKeyboard, &g_lpDIDevice, NULL); hr = g_lpDIDevice->SetDataFormat(&c_dfDIKeyboard); if FAILED(hr) return FALSE; // Set the cooperative level hr = g_lpDIDevice->SetCooperativeLevel(hWin, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE); if FAILED(hr) return FALSE; // Get access to the input device. hr = g_lpDIDevice->Acquire(); if FAILED(hr) return FALSE; }
//----------------------------------------------------------------------------- // Name: InitDirectInput() // Desc: Initialize the DirectInput variables. //----------------------------------------------------------------------------- HRESULT InitDirectInput( HWND hDlg ) { HRESULT hr; // Setup the g_EffectsList circular linked list ZeroMemory( &g_EffectsList, sizeof( EFFECTS_NODE ) ); g_EffectsList.pNext = &g_EffectsList; // Create a DInput object if( FAILED( hr = DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&g_pDI, NULL ) ) ) return hr; // Get the first enumerated force feedback device if( FAILED( hr = g_pDI->EnumDevices( 0, EnumFFDevicesCallback, 0, DIEDFL_ATTACHEDONLY | DIEDFL_FORCEFEEDBACK ) ) ) return hr; if( g_pFFDevice == NULL ) { MessageBox( hDlg, _T("No force feedback device found. ") _T("The sample will now exit."), _T("ReadFFE"), MB_ICONERROR | MB_OK ); EndDialog( hDlg, 0 ); return S_OK; } // Set the data format if( FAILED( hr = g_pFFDevice->SetDataFormat( &c_dfDIJoystick ) ) ) return hr; // Set the coop level if( FAILED( hr = g_pFFDevice->SetCooperativeLevel( hDlg, DISCL_EXCLUSIVE | DISCL_BACKGROUND ) ) ) return hr; // Disable auto-centering spring DIPROPDWORD dipdw; dipdw.diph.dwSize = sizeof(DIPROPDWORD); dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); dipdw.diph.dwObj = 0; dipdw.diph.dwHow = DIPH_DEVICE; dipdw.dwData = FALSE; if( FAILED( hr = g_pFFDevice->SetProperty( DIPROP_AUTOCENTER, &dipdw.diph ) ) ) return hr; // Acquire the device if( FAILED( hr = g_pFFDevice->Acquire() ) ) return hr; return S_OK; }
void ColoredCubeApp::initInput() { DirectInput8Create( mhAppInst, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&lpdi, NULL); lpdi->CreateDevice(GUID_SysMouseEm, &lpdiMouse, NULL); lpdiMouse->SetDataFormat(&c_dfDIMouse); lpdiMouse->SetCooperativeLevel(mhMainWnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND); }
void initialize(HWND hwnd_) { // DirectInputの作成 LPDIRECTINPUT8 keyboard = NULL; HRESULT hr = DirectInput8Create(::GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&keyboard, NULL); if (FAILED(hr)) { debug_out::trace("DirectInputオブジェクトの生成に失敗しました。"); throw nyx::com_exception("DirectInputオブジェクトの生成に失敗しました。", hr); } // デバイス・オブジェクトを作成 LPDIRECTINPUTDEVICE8 keyboardDevice = NULL; hr = keyboard->CreateDevice(GUID_SysKeyboard, &keyboardDevice, NULL); if (FAILED(hr)) { debug_out::trace("DirectInputDeviceオブジェクトの生成に失敗しました。"); throw nyx::com_exception("DirectInputDeviceオブジェクトの生成に失敗しました。", hr); } // データ形式を設定 hr = keyboardDevice->SetDataFormat(&c_dfDIKeyboard); if (FAILED(hr)) { debug_out::trace("データ形式の設定に失敗しました。"); throw nyx::com_exception("データ形式の設定に失敗しました。", hr); } //モードを設定(フォアグラウンド&非排他モード) hr = keyboardDevice->SetCooperativeLevel(hwnd_, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND); if (FAILED(hr)) { debug_out::trace("制御モードの設定に失敗しました。"); throw nyx::com_exception("制御モードの設定に失敗しました。", hr); } // バッファリング・データを取得するため、バッファ・サイズを設定 DIPROPDWORD diprop = {}; diprop.diph.dwSize = sizeof(diprop); diprop.diph.dwHeaderSize = sizeof(diprop.diph); diprop.diph.dwObj = 0; diprop.diph.dwHow = DIPH_DEVICE; diprop.dwData = 255; hr = keyboardDevice->SetProperty(DIPROP_BUFFERSIZE, &diprop.diph); if (FAILED(hr)) { debug_out::trace("バッファサイズの設定に失敗しました。"); throw nyx::com_exception("バッファサイズの設定に失敗しました。", hr); } keyboard_ = DirectInputPtr(keyboard, false); keyboardDevice_ = DirectInputDevicePtr(keyboardDevice, false); isInitialized = true; }
//============================================================================= // マウスの初期化 //============================================================================= HRESULT InitMouse(HINSTANCE hInst, HWND hWnd) { HRESULT hr; // デバイスオブジェクトを作成 hr = g_pDInput->CreateDevice(GUID_SysMouse, &g_pDIDevMouse, NULL); if(FAILED(hr)) { MessageBox(hWnd, "マウスがねぇ!", "警告!", MB_ICONWARNING); return hr; } // データフォーマットを設定 hr = g_pDIDevMouse->SetDataFormat(&c_dfDIMouse2); if(FAILED(hr)) { MessageBox(hWnd, "マウスのデータフォーマットを設定できませんでした。", "警告!", MB_ICONWARNING); return hr; } // 協調モードを設定(フォアグラウンド&非排他モード) hr = g_pDIDevMouse->SetCooperativeLevel(hWnd, (DISCL_FOREGROUND | DISCL_NONEXCLUSIVE)); if(FAILED(hr)) { MessageBox(hWnd, "マウスの協調モードを設定できませんでした。", "警告!", MB_ICONWARNING); return hr; } // デバイスのプロパティを設定 { DIPROPDWORD dipdw; dipdw.diph.dwSize = sizeof(dipdw); dipdw.diph.dwHeaderSize = sizeof(dipdw.diph); dipdw.diph.dwObj = 0; dipdw.diph.dwHow = DIPH_DEVICE; dipdw.dwData = DIPROPAXISMODE_REL; hr = g_pDIDevMouse->SetProperty(DIPROP_AXISMODE, &dipdw.diph); if(FAILED(hr)) { MessageBox(hWnd, "マウスのデバイスのプロパティを設定できませんでした。", "警告!", MB_ICONWARNING); return hr; } } // マウスへのアクセス権を獲得(入力制御開始) g_pDIDevMouse->Acquire(); return S_OK; }
int Init_Keyboard(HWND hwnd) { HRESULT result = dikeyboard->SetDataFormat(&c_dfDIKeyboard); result = dikeyboard->SetCooperativeLevel(hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND); if (result != DI_OK) return 0; result = dikeyboard->Acquire(); if (result != DI_OK) return 0; return 1; }
bool CG27::InitializeG27() { HRESULT hr; // Register with the DirectInput subsystem and get a pointer to a IDirectInput interface we can use. // Create a DInput object //initialize directinput library if( FAILED( hr = DirectInput8Create( GetModuleHandle( NULL ), DIRECTINPUT_VERSION, IID_IDirectInput8, ( VOID** )&g_pDI, NULL ) ) ) return false; LPDIRECTINPUTDEVICE8 joystick; // Look for the first simple joystick we can find. if (FAILED(hr = g_pDI->EnumDevices(DI8DEVCLASS_GAMECTRL, enumCallback, NULL, DIEDFL_ATTACHEDONLY))) { return false; } if (g_pJoystick == NULL) { // ShowMessageBox("g27 not found, please check the connection, exiting........"); qDebug() << "fucklrl"; return false; } if (FAILED(hr = g_pJoystick->SetDataFormat(&c_dfDIJoystick2))) { // ShowMessageBox(" set g27 data format error, exiting......."); qDebug() << "fuckld"; return false; } g_pJoystick->SetCooperativeLevel(NULL, DISCL_EXCLUSIVE|DISCL_FOREGROUND); DIDEVCAPS capabilities; capabilities.dwSize = sizeof(DIDEVCAPS); g_pJoystick->GetCapabilities(&capabilities); if (FAILED(hr=g_pJoystick->EnumObjects(enumAxesCallback, NULL, DIDFT_AXIS))) { } qDebug() << "initializing succeeded"; return true; }
int InitKeyboard (HWND hWnd) { HRESULT hr = diKeyboard->SetDataFormat(&c_dfDIKeyboard); if (hr != DI_OK) return 0; hr = diKeyboard->SetCooperativeLevel(hWnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND); if (hr != DI_OK) return 0; hr = diKeyboard->Acquire(); if (hr != DI_OK) return 0; return 1; }
int InitMouse (HWND hWnd) { HRESULT hr = diMouse->SetDataFormat(&c_dfDIMouse); if (hr != DI_OK) return 0; hr = diMouse->SetCooperativeLevel(hWnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND); if (hr != DI_OK) return 0; hr = diMouse->Acquire(); if (hr != DI_OK) return 0; return 1; }
//============================================================================= // キーボードの初期化 //============================================================================= HRESULT InitKeyboard(HINSTANCE hInstance, HWND hWnd) { HRESULT hr; // 入力処理の初期化 hr = InitInput(hInstance, hWnd); if(FAILED(hr)) { MessageBox(hWnd, "DirectInputオブジェクトが作れねぇ!", "警告!", MB_ICONWARNING); return hr; } // デバイスオブジェクトを作成 hr = g_pInput->CreateDevice(GUID_SysKeyboard, &g_pDevKeyboard, NULL); if(FAILED(hr)) { MessageBox(hWnd, "キーボードがねぇ!", "警告!", MB_ICONWARNING); return hr; } // データフォーマットを設定 hr = g_pDevKeyboard->SetDataFormat(&c_dfDIKeyboard); if(FAILED(hr)) { MessageBox(hWnd, "キーボードのデータフォーマットを設定できませんでした。", "警告!", MB_ICONWARNING); return hr; } // 協調モードを設定(フォアグラウンド&非排他モード) hr = g_pDevKeyboard->SetCooperativeLevel(hWnd, (DISCL_FOREGROUND | DISCL_NONEXCLUSIVE)); if(FAILED(hr)) { MessageBox(hWnd, "キーボードの協調モードを設定できませんでした。", "警告!", MB_ICONWARNING); return hr; } // キーボードへのアクセス権を獲得(入力制御開始) g_pDevKeyboard->Acquire(); // 各ワークのクリア ZeroMemory(g_aKeyState, sizeof g_aKeyState); ZeroMemory(g_aKeyStateTrigger, sizeof g_aKeyStateTrigger); ZeroMemory(g_aKeyStateRelease, sizeof g_aKeyStateRelease); ZeroMemory(g_aKeyStateRepeat, sizeof g_aKeyStateRepeat); ZeroMemory(g_aKeyStateRepeatCnt, sizeof g_aKeyStateRepeatCnt); return S_OK; }
void InitJoystick() { if(FAILED(DirectInput8Create ( GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&gDirectInput, NULL ) ) ) return; if(FAILED(gDirectInput->EnumDevices( DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, NULL, DIEDFL_ATTACHEDONLY ) ) ) return; if(!gJoystick) return; if( FAILED(gJoystick->SetDataFormat( &c_dfDIJoystick2 ) ) ) return; }