bool dx_init_mouse( void ) { HRESULT err; GUID guid_mouse = GUID_SysMouse; err = DirectInputCreate(GetModuleHandle(NULL), DIRECTINPUT_VERSION, &lpdi, NULL); if (FAILED(err)) return false; err = IDirectInput_CreateDevice(lpdi, &guid_mouse, &lpdiMouse, NULL); if ( err != DI_OK ) return false; err = IDirectInputDevice_SetDataFormat(lpdiMouse, &c_dfDIMouse); if(err != DI_OK) return false; err = IDirectInputDevice_SetCooperativeLevel( lpdiMouse, GetActiveWindow(), DISCL_NONEXCLUSIVE | DISCL_BACKGROUND ); if(err != DI_OK) return false; err = IDirectInputDevice_Acquire(lpdiMouse); return true; }
/* joystick_dinput_init: [primary thread] * Initialises the DirectInput joystick devices. */ static int joystick_dinput_init(void) { HRESULT hr; /* the DirectInput joystick interface is not part of DirectX 3 */ if (_dx_ver < 0x0500) return -1; /* get the DirectInput interface */ hr = DirectInputCreate(allegro_inst, DIRECTINPUT_VERSION, &joystick_dinput, NULL); if (FAILED(hr)) return -1; /* enumerate the joysticks attached to the system */ hr = IDirectInput_EnumDevices(joystick_dinput, DIDEVTYPE_JOYSTICK, joystick_enum_callback, NULL, DIEDFL_ATTACHEDONLY); if (FAILED(hr)) { IDirectInput_Release(joystick_dinput); return -1; } /* acquire the devices */ wnd_call_proc(joystick_dinput_acquire); return (dinput_joy_num == 0); }
bool DXGame::initDirectInput(HINSTANCE hInstance){ dprintf(("Entered initDirectInput\n")); if(FAILED(DirectInputCreate(hInstance, DIRECTINPUT_VERSION, &lpDirectInput, NULL))){ dprintf(("*****COULD NOT CREATE DIRECT INPUT OBJECT*****\n")); } if(FAILED(lpDirectInput->CreateDevice(GUID_SysKeyboard, &lpKeyboard, NULL))){ dprintf(("*****COULD NOT CREATE KEYBOARD*****\n")); } // set cooperation level if (lpKeyboard->SetCooperativeLevel(hwnd, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND)!=DI_OK){ dprintf(("COULD NOT SetCooperative Level\n")); return false; } // set data format if (lpKeyboard->SetDataFormat(&c_dfDIKeyboard)!=DI_OK){ dprintf(("COULD NOT Set Data Format\n")); return false; } // acquire the keyboard if (lpKeyboard->Acquire()!=DI_OK){ dprintf(("COULD NOT Acquire the keyboard\n")); return false; } dprintf(("Leaving the DirectInput\n")); return true; }
int PisteInput_Alusta(HWND &main_window_handle, HINSTANCE &hinstance_app) { if (PI_unload) { PI_main_window_handle = (HWND &) main_window_handle; PI_hinstance_app = (HINSTANCE &) hinstance_app; if (FAILED(DirectInputCreate(PI_hinstance_app, DIRECTINPUT_VERSION, &PI_lpdi, NULL))) { PisteLog_Kirjoita("[Error] Piste Input: DirectInputCreate failed! \n"); return PI_VIRHE; } /* Näppäimistön asennus */ if (!PisteInput_Alusta_Keyboard()) return PI_VIRHE; /* Hiiren asennus */ if (!PisteInput_Alusta_Mouse()) PI_mouse_available = false; //return PI_VIRHE; /* Ohjainten asennus */ PisteInput_Alusta_Ohjaimet(); PI_unload = false; } return 0; }
static void mouse_tests(void) { HRESULT hr; LPDIRECTINPUT pDI = NULL; HINSTANCE hInstance = GetModuleHandle(NULL); HWND hwnd; ULONG ref = 0; hr = DirectInputCreate(hInstance, DIRECTINPUT_VERSION, &pDI, NULL); if (hr == DIERR_OLDDIRECTINPUTVERSION) { skip("Tests require a newer dinput version\n"); return; } ok(SUCCEEDED(hr), "DirectInputCreate() failed: %08x\n", hr); if (FAILED(hr)) return; hwnd = CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW, 10, 10, 200, 200, NULL, NULL, NULL, NULL); ok(hwnd != NULL, "err: %d\n", GetLastError()); if (hwnd) { ShowWindow(hwnd, SW_SHOW); test_set_coop(pDI, hwnd); test_acquire(pDI, hwnd); DestroyWindow(hwnd); } if (pDI) ref = IUnknown_Release(pDI); ok(!ref, "IDirectInput_Release() reference count = %d\n", ref); }
INPUT_MASTER::INPUT_MASTER(HINSTANCE main_instance) { lpdi = NULL; INPUT_MASTER::main_instance = main_instance; if(DirectInputCreate(main_instance, DIRECTINPUT_VERSION, &lpdi, NULL) != DI_OK) throw ERROR("Unable to create Direct Input"); }
// Initialise the DXInput system BOOL DInpInitialise(void) { HRESULT hr; // DIDATAFORMAT sDataFormat; // Create the direct input object; hr = DirectInputCreate(hInstance, DIRECTINPUT_VERSION, &psDI, NULL); if (FAILED(hr)) { DBERROR(("DXInpInitialise: couldn't create DI object")); return FALSE; } hr = psDI->lpVtbl->CreateDevice(psDI, &GUID_SysMouse, &psDIMouse, NULL); if (FAILED(hr)) { DBERROR(("DXInpInitialise: couldn't create mouse object")); return FALSE; } /* memcpy(&sDataFormat, &c_dfDIMouse, sizeof(DIDATAFORMAT)); sDataFormat.dwFlags = DIDF_ABSAXIS; sDataFormat.dwSize = sizeof(DIDATAFORMAT); sDataFormat.dwObjSize = sizeof(DIOBJECTDATAFORMAT); sDataFormat.dwDataSize = 0; sDataFormat.dwNumObjs = 0; sDataFormat.rgodf = NULL;*/ hr = psDIMouse->lpVtbl->SetDataFormat(psDIMouse, &c_dfDIMouse);//&sDataFormat); if (FAILED(hr)) { DBERROR(("DXInpInitialise: couldn't set mouse format")); return FALSE; } hr = psDIMouse->lpVtbl->SetCooperativeLevel(psDIMouse, hWndMain, DISCL_EXCLUSIVE | DISCL_FOREGROUND); if (FAILED(hr)) { DBERROR(("DXInpInitialise: couldn't set mouse cooperative level")); return FALSE; } DIMouseAcquired = FALSE; if (!DInpMouseAcc(DINP_MOUSEACQUIRE)) { DBERROR(("DXInpInitialise: couldn't acquire mouse")); return FALSE; } mickeyScale = DINP_MOUSESCALE; mickeyX = (SDWORD)screenWidth * mickeyScale / 2; mickeyY = (SDWORD)screenHeight * mickeyScale / 2; return TRUE; }
InputHandler_DInput::InputHandler_DInput() { LOG->Trace( "InputHandler_DInput::InputHandler_DInput()" ); CheckForDirectInputDebugMode(); shutdown = false; g_NumJoysticks = 0; AppInstance inst; HRESULT hr = DirectInputCreate(inst.Get(), DIRECTINPUT_VERSION, &dinput, NULL); if ( hr != DI_OK ) RageException::Throw( hr_ssprintf(hr, "InputHandler_DInput: DirectInputCreate") ); LOG->Trace( "InputHandler_DInput: IDirectInput::EnumDevices(DIDEVTYPE_KEYBOARD)" ); hr = dinput->EnumDevices( DIDEVTYPE_KEYBOARD, EnumDevices, NULL, DIEDFL_ATTACHEDONLY ); if ( hr != DI_OK ) RageException::Throw( hr_ssprintf(hr, "InputHandler_DInput: IDirectInput::EnumDevices") ); LOG->Trace( "InputHandler_DInput: IDirectInput::EnumDevices(DIDEVTYPE_JOYSTICK)" ); hr = dinput->EnumDevices( DIDEVTYPE_JOYSTICK, EnumDevices, NULL, DIEDFL_ATTACHEDONLY ); if ( hr != DI_OK ) RageException::Throw( hr_ssprintf(hr, "InputHandler_DInput: IDirectInput::EnumDevices") ); for( unsigned i = 0; i < Devices.size(); ++i ) { if( Devices[i].Open() ) continue; Devices.erase( Devices.begin() + i ); i--; continue; } LOG->Info( "Found %u DirectInput devices:", Devices.size() ); for( unsigned i = 0; i < Devices.size(); ++i ) { LOG->Info( " %d: '%s' axes: %d, hats: %d, buttons: %d (%s)", i, Devices[i].JoystickInst.tszProductName, Devices[i].axes, Devices[i].hats, Devices[i].buttons, Devices[i].buffered? "buffered": "unbuffered" ); } m_DebugTimer.m_sName = "DirectInput"; StartThread(); }
//----------------------------------------------------------------------------- // Function: InitDirectInput // // Description: // Initialize the DirectInput variables. // //----------------------------------------------------------------------------- r_val MouseManInit(HINSTANCE hInst,HWND hwnd) { HRESULT hr; ////static bool com_init=false; ////if (!com_init) //{ // // Initialize COM. // if( FAILED(hr=CoInitialize(NULL)) ) // return r_err; // //com_init=true; //} // Register with the DirectInput subsystem and get a pointer // to a IDirectInput interface we can use. hr = DirectInputCreate( hInst, DIRECTINPUT_VERSION, &g_pDI, NULL ); if ( FAILED(hr) ) return HErrorN("DirectInputCreate"); // Obtain an interface to the system mouse device. hr = g_pDI->CreateDevice( GUID_SysMouse, &g_pMouse, NULL ); if ( FAILED(hr) ) return HErrorN("DirectInput::CreateDevice"); // 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. hr = g_pMouse->SetDataFormat( &c_dfDIMouse ); if ( FAILED(hr) ) return HErrorN("DirectInputMouse::SetDataFormat"); // Set the cooperativity level to let DirectInput know how // this device should interact with the system and with other // DirectInput applications. hr = g_pMouse->SetCooperativeLevel( hwnd, //DISCL_NONEXCLUSIVE | DISCL_FOREGROUND); DISCL_EXCLUSIVE | DISCL_FOREGROUND); if ( FAILED(hr) ) return HErrorN("DirectInputMouse::SetCooperativeLevel"); g_pMouse->Acquire(); return r_ok; }
BOOL InitialiseDirectInput(void) { // try to create di object if (DirectInputCreate(hInst, DIRECTINPUT_VERSION, &lpdi, NULL) != DI_OK) { #if debug ReleaseDirect3D(); exit(0x4111); #else return FALSE; #endif } return TRUE; }
JoystickDriver_DX5::JoystickDriver_DX5(bool exclude_xinput) : dii(NULL) { enum_device_list edl; std::set<uint32> exclude_vps; try { REQUIRE_DI_CALL( DirectInputCreate(GetModuleHandle(NULL), DIRECTINPUT_VERSION, &dii, NULL) ); REQUIRE_DI_CALL( dii->EnumDevices(DIDEVTYPE_JOYSTICK, GLOB_EnumJoysticksProc, &edl, DIEDFL_ATTACHEDONLY) ); if(exclude_xinput) { exclude_vps = GetXInputVidPid(); } for(unsigned i = 0; i < edl.valid_count; i++) { Joystick_DX5 *jdx5 = NULL; if(edl.ddi[i].guidProduct.Data1 && exclude_vps.count(edl.ddi[i].guidProduct.Data1)) continue; try { jdx5 = new Joystick_DX5(dii, &edl.ddi[i]); joys.push_back(jdx5); } catch(std::exception &e) { MDFND_PrintError(e.what()); if(jdx5 != NULL) { delete jdx5; jdx5 = NULL; } } } } catch(std::exception &e) { MDFND_PrintError(e.what()); } }
HRESULT InitDirectInput( HANDLE hInstance, HWND hWnd ) { HRESULT hr; DIPROPDWORD propWord; /* connect to direct input */ hr = DirectInputCreate( hInstance, DIRECTINPUT_VERSION, &lpDI, NULL ); ERROR_CHECK(hr, "Error creating DirectInput object"); /* get the mouse */ hr = lpDI->lpVtbl->CreateDevice(lpDI, &GUID_SysMouse, &lpDev, NULL ); ERROR_CHECK(hr, "Error creating DirectDevice object (mouse)"); /* tell it to get us mouse format data */ hr = lpDev->lpVtbl->SetDataFormat(lpDev, &c_dfDIMouse ); ERROR_CHECK(hr, "Error setting data format"); /* be quite cooperative */ hr = lpDev->lpVtbl->SetCooperativeLevel(lpDev, hWnd, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND); ERROR_CHECK(hr, "Error setting cooperative level"); /* setup buffer size */ propWord.diph.dwSize = sizeof(DIPROPDWORD); propWord.diph.dwHeaderSize = sizeof(DIPROPHEADER); propWord.diph.dwObj = 0; propWord.diph.dwHow = DIPH_DEVICE; propWord.dwData = BUFFER_SIZE; hr = lpDev->lpVtbl->SetProperty(lpDev, DIPROP_BUFFERSIZE, &propWord.diph ); ERROR_CHECK(hr, "Error setting input buffer size"); /* try to aquire the device right away */ lpDev->lpVtbl->Acquire(lpDev); return S_OK; }
static void joystick_tests(DWORD version) { HRESULT hr; LPDIRECTINPUT pDI; ULONG ref; HINSTANCE hInstance = GetModuleHandle(NULL); trace("-- Testing Direct Input Version 0x%04x --\n", version); hr = DirectInputCreate(hInstance, version, &pDI, NULL); ok(hr==DI_OK||hr==DIERR_OLDDIRECTINPUTVERSION, "DirectInputCreate() failed: %08x\n", hr); if (hr==DI_OK && pDI!=0) { UserData data; data.pDI = pDI; data.version = version; hr = IDirectInput_EnumDevices(pDI, DIDEVTYPE_JOYSTICK, EnumJoysticks, &data, DIEDFL_ALLDEVICES); ok(hr==DI_OK,"IDirectInput_EnumDevices() failed: %08x\n", hr); ref = IDirectInput_Release(pDI); ok(ref==0,"IDirectInput_Release() reference count = %d\n", ref); } else if (hr==DIERR_OLDDIRECTINPUTVERSION) trace(" Version Not Supported\n"); }
void key_init() { HRESULT hr; // my kingdom, my kingdom for C++... if (SUCCEEDED (hr = DirectInputCreate (GetModuleHandle (NULL), DIRECTINPUT_VERSION, &g_lpdi, NULL))) { if (SUCCEEDED (hr = IDirectInput_CreateDevice (g_lpdi, (void *)&GUID_SysKeyboard, &g_lpdidKeybd, NULL))) { DIPROPDWORD dipdw; dipdw.diph.dwSize = sizeof (DIPROPDWORD); dipdw.diph.dwHeaderSize = sizeof (DIPROPHEADER); dipdw.diph.dwObj = 0; dipdw.diph.dwHow = DIPH_DEVICE; dipdw.dwData = 40; if (SUCCEEDED (hr = IDirectInputDevice_SetDataFormat (g_lpdidKeybd, &c_dfDIKeyboard)) && SUCCEEDED (hr = IDirectInputDevice_SetCooperativeLevel (g_lpdidKeybd, g_hWnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND)) && SUCCEEDED (hr = IDirectInputDevice_SetProperty (g_lpdidKeybd, DIPROP_BUFFERSIZE, &dipdw.diph)) && SUCCEEDED (hr = IDirectInputDevice_Acquire (g_lpdidKeybd))) { // fine WMKey_Handler_Ready = 1; // Clear the keyboard array KeyFlush(); atexit(key_close); } else { IDirectInputDevice_Release (g_lpdidKeybd); g_lpdidKeybd = NULL; } } } }
/*------------------------------------------------------------------------------*/ BOOL AkindDI::Init( HWND hWnd, BOOL BackGround ) { HRESULT hRes; HINSTANCE hInstance = GetModuleHandle( NULL ); m_hWnd = hWnd; m_JoyNum = 0; m_BackGround = BackGround; ZeroMemory( m_KeyBuff, sizeof(m_KeyBuff) ); ZeroMemory( m_JoyGUID, sizeof(m_JoyGUID) ); ZeroMemory( m_JoyData, sizeof(m_JoyData) ); for ( int i=0; i<JOY_MAX; i++ ){ m_JoyReady[i] = FALSE; } hRes = DirectInputCreate( hInstance, DIRECTINPUT_VERSION, &m_pDInput, NULL ); if ( FAILED( hRes ) ){ Error( 0, hRes ); return( FALSE ); } hRes = m_pDInput->CreateDevice( GUID_SysKeyboard, &m_pDInputKey, NULL ); if ( FAILED( hRes ) ){ Error( 1, hRes ); return( FALSE ); } hRes = m_pDInputKey->SetDataFormat( &c_dfDIKeyboard ); if ( FAILED( hRes ) ){ Error( 2, hRes ); return( FALSE ); } if ( m_BackGround ){ hRes = m_pDInputKey->SetCooperativeLevel( hWnd, DISCL_BACKGROUND|DISCL_NONEXCLUSIVE ); } else { hRes = m_pDInputKey->SetCooperativeLevel( hWnd, DISCL_FOREGROUND|DISCL_NONEXCLUSIVE ); } if ( FAILED( hRes ) ){ Error( 3, hRes ); return( FALSE ); } JoyAdd(); DEV_BROADCAST_DEVICEINTERFACE filter; filter.dbcc_size = sizeof(filter); filter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; filter.dbcc_classguid = GUID_CLASS_INPUT; RegisterDeviceNotification( hWnd, &filter, DEVICE_NOTIFY_WINDOW_HANDLE ); return( TRUE ); }
/* mouse_dinput_init: [primary thread] * Sets up the DirectInput mouse device. */ static int mouse_dinput_init(void) { HRESULT hr; DIPROPDWORD property_buf_size = { /* the header */ { sizeof(DIPROPDWORD), // diph.dwSize sizeof(DIPROPHEADER), // diph.dwHeaderSize 0, // diph.dwObj DIPH_DEVICE, // diph.dwHow }, /* the data */ DINPUT_BUFFERSIZE, // dwData }; /* Get DirectInput interface */ hr = DirectInputCreate(allegro_inst, DIRECTINPUT_VERSION, &mouse_dinput, NULL); if (FAILED(hr)) goto Error; /* Create the mouse device */ hr = IDirectInput_CreateDevice(mouse_dinput, &GUID_SysMouse, &mouse_dinput_device, NULL); if (FAILED(hr)) goto Error; /* Find how many buttons */ dinput_buttons = 0; dinput_wheel = FALSE; hr = IDirectInputDevice_EnumObjects(mouse_dinput_device, mouse_enum_callback, NULL, DIDFT_PSHBUTTON | DIDFT_AXIS); if (FAILED(hr)) goto Error; /* Check to see if the buttons are swapped (left-hand) */ mouse_swap_button = GetSystemMetrics(SM_SWAPBUTTON); /* Set data format */ hr = IDirectInputDevice_SetDataFormat(mouse_dinput_device, &c_dfDIMouse); if (FAILED(hr)) goto Error; /* Set buffer size */ hr = IDirectInputDevice_SetProperty(mouse_dinput_device, DIPROP_BUFFERSIZE, &property_buf_size.diph); if (FAILED(hr)) goto Error; /* Enable event notification */ mouse_input_event = CreateEvent(NULL, FALSE, FALSE, NULL); hr = IDirectInputDevice_SetEventNotification(mouse_dinput_device, mouse_input_event); if (FAILED(hr)) goto Error; /* Register event handler */ if (_win_input_register_event(mouse_input_event, mouse_dinput_handle) != 0) goto Error; /* Grab the device */ _mouse_on = TRUE; wnd_call_proc(mouse_dinput_grab); return 0; Error: mouse_dinput_exit(); return -1; }
bool joysticks_init(void) { HRESULT err; DIPROPDWORD dipdw = { { sizeof(DIPROPDWORD), // diph.dwSize sizeof(DIPROPHEADER), // diph.dwHeaderSize 0, // diph.dwObj DIPH_DEVICE, // diph.dwHow }, DINPUT_BUFFERSIZE, // dwData }; LPDIRECTINPUTDEVICE tempJoystick = NULL; LPVOID joysticknumptr; int i, j, k; bool failjoystick; err = DirectInputCreate(GetModuleHandle(NULL), DIRECTINPUT_VERSION, &lpdi, NULL); if (FAILED(err))//DirectInput8Create(hInstApp, DIRECTINPUT_VERSION, &IID_IDirectInput8, (void**)&lpdi, NULL))) { return false; } // try to create Joystick devices for ( i = 0; i < MAX_JOYSTICKS; i++ ) lpdiJoystick[i] = NULL; Num_Joysticks = 0; lpdi->lpVtbl->EnumDevices(lpdi, DIDEVTYPE_JOYSTICK, //DI8DEVCLASS_GAMECTRL, InitJoystickInput, lpdi, DIEDFL_ATTACHEDONLY); failjoystick = false; for (i = 0; i < Num_Joysticks; i++) { JoystickInfo[i].assigned = false; JoystickInfo[i].connected = true; JoystickInfo[i].NumAxis = 0; JoystickInfo[i].NumButtons = 0; JoystickInfo[i].NumPOVs = 0; joysticknumptr = (LPVOID)&i; for (j = AXIS_Start; j <= AXIS_End; j++) { JoystickInfo[i].Axis[j].exists = false; } lpdiJoystick[i]->lpVtbl->EnumObjects(lpdiJoystick[i], DIEnumDeviceObjectsProc, joysticknumptr, DIDFT_ALL); for (j = AXIS_Start; j <= AXIS_End; j++) { JoystickInfo[i].Axis[j].action = SHIPACTION_Nothing; JoystickInfo[i].Axis[j].inverted = false; JoystickInfo[i].Axis[j].deadzone = 20; JoystickInfo[i].Axis[j].fine = true; } for (j = 0; j < JoystickInfo[i].NumButtons; j++) JoystickInfo[i].Button[j].action = SHIPACTION_Nothing; for (j = 0; j < JoystickInfo[i].NumPOVs; j++) { for (k = 0; k < MAX_POV_DIRECTIONS; k++) JoystickInfo[i].POV[j].action[k] = SHIPACTION_Nothing; } // Tell DirectInput that we want to receive data in joystick format if (IDirectInputDevice2_SetDataFormat(lpdiJoystick[i], &c_dfDIJoystick2) == DI_OK) { // set cooperative level if(IDirectInputDevice2_SetCooperativeLevel(lpdiJoystick[i], GetActiveWindow(), DISCL_NONEXCLUSIVE | DISCL_FOREGROUND) == DI_OK) { // try to acquire the Joystick err = IDirectInputDevice2_Acquire(lpdiJoystick[i]); if (err != DI_OK) { failjoystick = true; } }else { failjoystick = true; } } else { failjoystick = true; } if (failjoystick) { failjoystick = false; IDirectInputDevice2_Release(lpdiJoystick[i]); lpdiJoystick[i] = NULL; } } DebugPrintf( "joysticks_init: %d joysticks connected\n", Num_Joysticks ); // if we get here, all DirectInput objects were created ok return true; }
InputEngineImpl(HWND hwnd) : m_hwnd(hwnd), m_bFocus(false) { // // Create the direct input object // #ifdef Dynamic_DInput m_hdinput = ::LoadLibrary("dinput.dll"); ZAssert(m_hdinput != NULL); PFNDirectInputCreate pfn = (PFNDirectInputCreate)::GetProcAddress(m_hdinput, "DirectInputCreateA"); ZAssert(pfn != NULL); DDCall(pfn( GetModuleHandle(NULL), DIRECTINPUT_VERSION, &m_pdi, NULL )); // // grab the address of a few dinput globals // // g_pdfDIMouse = (DIDATAFORMAT*)::GetProcAddress(m_hdinput, "c_dfDIMouse"); g_pdfDIMouse = (DIDATAFORMAT*)::GetProcAddress(m_hdinput, "c_dfDIMouse2"); // mdvalley: Mouse2 for more buttons ZAssert(g_pdfDIMouse != NULL); #else DDCall(DirectInputCreate( GetModuleHandle(NULL), DIRECTINPUT_VERSION, &m_pdi, NULL )); //DDCall(DirectInput8Create( // KG - Di8 update // GetModuleHandle(NULL), // DIRECTINPUT_VERSION, // IID_IDirectInput8, // (LPVOID*)&m_pdi, // NULL // )); // g_pdfDIMouse = &c_dfDIMouse; g_pdfDIMouse = &c_dfDIMouse2; // mdvalley: Mouse2 for more buttons #endif // // If we failed then exit the app // if (m_pdi == NULL) { ::MessageBox(NULL, "Error initializing DirectInput. Check your installation", "Error", MB_OK); _exit(0); } // // Enumerate the devices // EnumerateJoysticks(); }
qboolean IN_InitDInput(void) { HRESULT hResult; DIPROPDWORD dipdw = { { sizeof(DIPROPDWORD), // diph.dwSize sizeof(DIPROPHEADER), // diph.dwHeaderSize 0, // diph.dwObj DIPH_DEVICE, // diph.dwHow } , DINPUT_BUFFERSIZE, // dwData }; #ifdef __GNUC__ hResult = DirectInputCreate(g_wv.hInstance, DIRECTINPUT_VERSION, &g_pdi, NULL); #else hResult = DirectInput8Create(g_wv.hInstance, DIRECTINPUT_VERSION, &IID_IDirectInput8A, &g_pdi, NULL); #endif if(FAILED(hResult)) { #ifdef __GNUC__ Com_Printf("DirectInput8Create failed\n"); #else Com_Printf("DirectInput8Create failed\n"); #endif return qfalse; } // obtain an interface to the system mouse device. hResult = IDirectInput_CreateDevice(g_pdi, &GUID_SysMouse, &g_pMouse, NULL); if(FAILED(hResult)) { Com_Printf("Couldn't open DI mouse device\n"); return qfalse; } // set the data format to "mouse format". hResult = IDirectInputDevice_SetDataFormat(g_pMouse, &df); if(FAILED(hResult)) { Com_Printf("Couldn't set DI mouse format\n"); return qfalse; } // set the DirectInput cooperativity level. hResult = IDirectInputDevice_SetCooperativeLevel(g_pMouse, g_wv.hWnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND); if(FAILED(hResult)) { Com_Printf("Couldn't set DI coop level\n"); return qfalse; } // set the buffer size to DINPUT_BUFFERSIZE elements. // the buffer size is a DWORD property associated with the device hResult = IDirectInputDevice_SetProperty(g_pMouse, DIPROP_BUFFERSIZE, &dipdw.diph); if(FAILED(hResult)) { Com_Printf("Couldn't set DI buffersize\n"); return qfalse; } return qtrue; }
/** * input_dinput_init(): Initialize the DirectInput subsystem. * @return 0 on success; non-zero on error. */ int input_dinput_init(void) { int i; HRESULT rval; // Attempt to initialize DirectInput 5. input_dinput_version = 0; rval = DirectInputCreate(ghInstance, DIRECTINPUT_VERSION_5, &lpDI, NULL); if (rval == DI_OK) { // DirectInput 5 initialized. LOG_MSG(input, LOG_MSG_LEVEL_INFO, "Initialized DirectInput 5."); input_dinput_version = DIRECTINPUT_VERSION_5; } else { // Attempt to initialize DirectInput 3. rval = DirectInputCreate(ghInstance, DIRECTINPUT_VERSION_3, &lpDI, NULL); if (rval == DI_OK) { // DirectInput 3 initialized. LOG_MSG(input, LOG_MSG_LEVEL_INFO, "Initialized DirectInput 3."); input_dinput_version = DIRECTINPUT_VERSION_3; } else { // DirectInput could not be initialized. LOG_MSG(input, LOG_MSG_LEVEL_CRITICAL, "Could not initialize DirectInput 3 or DirectInput 5.\n\nYou must have DirectX 3 or later."); return -1; } } input_dinput_joystick_initialized = false; input_dinput_joystick_error = false; input_dinput_num_joysticks = 0; memset(input_dinput_joy_id, 0x00, sizeof(input_dinput_joy_id)); //rval = lpDI->CreateDevice(GUID_SysMouse, &lpDIDMouse, NULL); lpDIDMouse = NULL; rval = lpDI->CreateDevice(GUID_SysKeyboard, &lpDIDKeyboard, NULL); if (rval != DI_OK) { LOG_MSG(input, LOG_MSG_LEVEL_CRITICAL, "lpDI->CreateDevice() failed. (Keyboard)"); // TODO: Use cross-platform error numbers, not just DirectInput return values. return -2; } // Set the cooperative level. input_dinput_set_cooperative_level(NULL); //rval = lpDIDMouse->SetDataFormat(&c_dfDIMouse); rval = lpDIDKeyboard->SetDataFormat(&c_dfDIKeyboard); if (rval != DI_OK) { LOG_MSG(input, LOG_MSG_LEVEL_CRITICAL, "lpDIDKeyboard->SetDataFormat() failed."); // TODO: Use cross-platform error numbers, not just DirectInput return values. return -1; } //rval = lpDIDMouse->Acquire(); for(i = 0; i < 10; i++) { rval = lpDIDKeyboard->Acquire(); if (rval == DI_OK) break; GensUI::sleep(10); } // Clear the DirectInput arrays. memset(input_dinput_keys, 0x00, sizeof(input_dinput_keys)); memset(input_dinput_joy_id, 0x00, sizeof(input_dinput_joy_id)); memset(input_dinput_joy_state, 0x00, sizeof(input_dinput_joy_state)); // DirectInput initialized. return 0; }
/* key_dinput_init: [primary thread] * Sets up the DirectInput keyboard device. */ static int key_dinput_init(void) { HRESULT hr; HWND allegro_wnd = win_get_window(); DIPROPDWORD property_buf_size = { /* the header */ { sizeof(DIPROPDWORD), // diph.dwSize sizeof(DIPROPHEADER), // diph.dwHeaderSize 0, // diph.dwObj DIPH_DEVICE, // diph.dwHow }, /* the data */ DINPUT_BUFFERSIZE, // dwData }; /* Get DirectInput interface */ hr = DirectInputCreate(allegro_inst, DIRECTINPUT_VERSION, &key_dinput, NULL); if (FAILED(hr)) goto Error; /* Create the keyboard device */ hr = IDirectInput_CreateDevice(key_dinput, &GUID_SysKeyboard, &key_dinput_device, NULL); if (FAILED(hr)) goto Error; /* Set data format */ hr = IDirectInputDevice_SetDataFormat(key_dinput_device, &c_dfDIKeyboard); if (FAILED(hr)) goto Error; /* Set buffer size */ hr = IDirectInputDevice_SetProperty(key_dinput_device, DIPROP_BUFFERSIZE, &property_buf_size.diph); if (FAILED(hr)) goto Error; /* Set cooperative level */ hr = IDirectInputDevice_SetCooperativeLevel(key_dinput_device, allegro_wnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE); if (FAILED(hr)) goto Error; /* Enable event notification */ key_input_event = CreateEvent(NULL, FALSE, FALSE, NULL); hr = IDirectInputDevice_SetEventNotification(key_dinput_device, key_input_event); if (FAILED(hr)) goto Error; /* Register event handler */ if (_win_input_register_event(key_input_event, key_dinput_handle) != 0) goto Error; get_reverse_mapping(); /* Acquire the device */ wnd_call_proc(key_dinput_acquire); return 0; Error: key_dinput_exit(); return -1; }
int di_init() { HRESULT hr; return 0; /* * Register with the DirectInput subsystem and get a pointer * to a IDirectInput interface we can use. * * Parameters: * * g_hinst * * Instance handle to our application or DLL. * * DIRECTINPUT_VERSION * * The version of DirectInput we were designed for. * We take the value from the <dinput.h> header file. * * &g_pdi * * Receives pointer to the IDirectInput interface * that was created. * * NULL * * We do not use OLE aggregation, so this parameter * must be NULL. * */ hr = DirectInputCreate(GetModuleHandle(NULL), 0x300, &Di_object, NULL); if (FAILED(hr)) { mprintf(( "DirectInputCreate failed!\n" )); return FALSE; } /* * Obtain an interface to the system keyboard device. * * Parameters: * * GUID_SysKeyboard * * The instance GUID for the device we wish to access. * GUID_SysKeyboard is a predefined instance GUID that * always refers to the system keyboard device. * * &g_pKeyboard * * Receives pointer to the IDirectInputDevice interface * that was created. * * NULL * * We do not use OLE aggregation, so this parameter * must be NULL. * */ hr = Di_object->CreateDevice(GUID_SysKeyboard, &Di_keyboard, NULL); if (FAILED(hr)) { mprintf(( "CreateDevice failed!\n" )); return FALSE; } /* * Set the data format to "keyboard 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 an array * of 256 bytes to IDirectInputDevice::GetDeviceState. * * Parameters: * * c_dfDIKeyboard * * Predefined data format which describes * an array of 256 bytes, one per scancode. */ hr = Di_keyboard->SetDataFormat(&c_dfDIKeyboard); if (FAILED(hr)) { mprintf(( "SetDataFormat failed!\n" )); return FALSE; } /* * Set the cooperativity level to let DirectInput know how * this device should interact with the system and with other * DirectInput applications. * * Parameters: * * DISCL_NONEXCLUSIVE * * Retrieve keyboard data when acquired, not interfering * with any other applications which are reading keyboard * data. * * DISCL_FOREGROUND * * If the user switches away from our application, * automatically release the keyboard back to the system. * */ hr = Di_keyboard->SetCooperativeLevel((HWND)os_get_window(), DISCL_NONEXCLUSIVE | DISCL_FOREGROUND); if (FAILED(hr)) { mprintf(( "SetCooperativeLevel failed!\n" )); return FALSE; } DIPROPDWORD hdr; // Turn on buffering hdr.diph.dwSize = sizeof(DIPROPDWORD); hdr.diph.dwHeaderSize = sizeof(DIPROPHEADER); hdr.diph.dwObj = 0; hdr.diph.dwHow = DIPH_DEVICE; // Apply to entire device hdr.dwData = 16; //MAX_BUFFERED_KEYBOARD_EVENTS; hr = Di_keyboard->SetProperty( DIPROP_BUFFERSIZE, &hdr.diph ); if (FAILED(hr)) { mprintf(( "SetProperty DIPROP_BUFFERSIZE failed\n" )); return FALSE; } Di_event = CreateEvent( NULL, FALSE, FALSE, NULL ); Assert(Di_event != NULL); Di_thread = CreateThread(NULL, 1024, (LPTHREAD_START_ROUTINE)di_process, NULL, 0, &Di_thread_id); Assert( Di_thread != NULL ); SetThreadPriority(Di_thread, THREAD_PRIORITY_HIGHEST); hr = Di_keyboard->SetEventNotification(Di_event); if (FAILED(hr)) { mprintf(( "SetEventNotification failed\n" )); return FALSE; } Di_keyboard->Acquire(); return TRUE; }
int di_init() { HRESULT hr; if (Mouse_mode == MOUSE_MODE_WIN){ return 0; } Di_mouse_inited = 0; hr = DirectInputCreate(GetModuleHandle(NULL), DIRECTINPUT_VERSION, &Di_mouse_obj, NULL); if (FAILED(hr)) { hr = DirectInputCreate(GetModuleHandle(NULL), 0x300, &Di_mouse_obj, NULL); if (FAILED(hr)) { mprintf(( "DirectInputCreate() failed!\n" )); return FALSE; } } hr = Di_mouse_obj->CreateDevice(GUID_SysMouse, &Di_mouse, NULL); if (FAILED(hr)) { mprintf(( "CreateDevice() failed!\n" )); return FALSE; } hr = Di_mouse->SetDataFormat(&c_dfDIMouse); if (FAILED(hr)) { mprintf(( "SetDataFormat() failed!\n" )); return FALSE; } hr = Di_mouse->SetCooperativeLevel((HWND)os_get_window(), DISCL_NONEXCLUSIVE | DISCL_FOREGROUND); if (FAILED(hr)) { mprintf(( "SetCooperativeLevel() failed!\n" )); return FALSE; } /* DIPROPDWORD hdr; // Turn on buffering hdr.diph.dwSize = sizeof(DIPROPDWORD); hdr.diph.dwHeaderSize = sizeof(DIPROPHEADER); hdr.diph.dwObj = 0; hdr.diph.dwHow = DIPH_DEVICE; // Apply to entire device hdr.dwData = 16; //MAX_BUFFERED_KEYBOARD_EVENTS; hr = Di_mouse->SetProperty( DIPROP_BUFFERSIZE, &hdr.diph ); if (FAILED(hr)) { mprintf(( "SetProperty DIPROP_BUFFERSIZE failed\n" )); return FALSE; } Di_event = CreateEvent( NULL, FALSE, FALSE, NULL ); Assert(Di_event != NULL); hr = Di_mouse->SetEventNotification(Di_event); if (FAILED(hr)) { mprintf(( "SetEventNotification failed\n" )); return FALSE; } */ Di_mouse->Acquire(); Di_mouse_inited = 1; return TRUE; }