void DirectInput_Update() { //update the mouse dimouse->GetDeviceState(sizeof(mouseState), (LPVOID)&mouseState); //update the keyboard dikeyboard->GetDeviceState(sizeof(keys), (LPVOID)&keys); }
int GutReadMouse(GutMouseInfo *info) { if( NULL == g_pMouse ) return 0; // DirectInput mouse state structure DIMOUSESTATE2 dims2; // Get the input's device state, and put the state in dims ZeroMemory( &dims2, sizeof(dims2) ); int hr = g_pMouse->GetDeviceState( sizeof(DIMOUSESTATE2), &dims2 ); if ( FAILED(hr) ) { g_pMouse->Acquire(); g_pMouse->GetDeviceState( sizeof(DIMOUSESTATE2), &dims2 ); } info->x = dims2.lX; info->y = dims2.lY; info->z = dims2.lZ; g_mouse.x += info->x; g_mouse.y += info->y; info->button[0] = dims2.rgbButtons[0] & 0x80 ? 1 : 0; info->button[1] = dims2.rgbButtons[1] & 0x80 ? 1 : 0; info->button[2] = dims2.rgbButtons[2] & 0x80 ? 1 : 0; return 1; }
void DirectInput_Update() { //update mouse dimouse->Poll(); if (!SUCCEEDED(dimouse->GetDeviceState(sizeof(DIMOUSESTATE),&mouse_state))) { //mouse device lose, try to re-acquire dimouse->Acquire(); } //update keyboard dikeyboard->Poll(); if (!SUCCEEDED(dikeyboard->GetDeviceState(256,(LPVOID)&keys))) { //keyboard device lost, try to re-acquire dikeyboard->Acquire(); } //update controllers for (int i=0; i< 4; i++ ) { ZeroMemory( &controllers[i], sizeof(XINPUT_STATE) ); //get the state of the controller XINPUT_STATE state; DWORD result = XInputGetState( i, &state ); //store state in global controllers array if (result == 0) controllers[i] = state.Gamepad; } }
void getState() { if(mouseDevice->GetDeviceState(sizeof(mouseState), (LPVOID)&mouseState ) == DIERR_INPUTLOST) { mouseDevice->Acquire(); } if(keyboardDevice->GetDeviceState(sizeof(keyState), (LPVOID)&keyState ) == DIERR_INPUTLOST) { mouseDevice->Acquire(); } mousePosX += mouseState.lX; mousePosY += mouseState.lY; }
//============================================================================= // マウスの更新処理 //============================================================================= HRESULT UpdateMouse(void) { HRESULT hr; DIMOUSESTATE2 mouseState; // デバイスからデータを取得 hr = g_pDIDevMouse->GetDeviceState(sizeof(mouseState), &mouseState); if(SUCCEEDED(hr)) { g_mouseStateTrigger.lX = ((g_mouseState.lX ^ mouseState.lX) & mouseState.lX); g_mouseStateTrigger.lY = ((g_mouseState.lY ^ mouseState.lY) & mouseState.lY); g_mouseStateTrigger.lZ = ((g_mouseState.lZ ^ mouseState.lZ) & mouseState.lZ); for(int nCntKey = 0; nCntKey < NUM_MOUSE_BUTTON_MAX; nCntKey++) { g_mouseStateTrigger.rgbButtons[nCntKey] = ((g_mouseState.rgbButtons[nCntKey] ^ mouseState.rgbButtons[nCntKey]) & mouseState.rgbButtons[nCntKey]); } g_mouseState = mouseState; } else { // マウスへのアクセス権を獲得(入力制御開始) g_pDIDevMouse->Acquire(); } return S_OK; }
int DInput_Read_Joystick(void) { // this function reads the joystick state // make sure the joystick was initialized if (!joystick_found) return(0); if (lpdijoy) { // this is needed for joysticks only if (lpdijoy->Poll()!=DI_OK) return(0); if (lpdijoy->GetDeviceState(sizeof(DIJOYSTATE), (LPVOID)&joy_state)!=DI_OK) return(0); } else { // joystick isn't plugged in, zero out state memset(&joy_state,0,sizeof(joy_state)); // return error return(0); } // end else // return sucess return(1); } // end DInput_Read_Joystick
static void Mouse_Win32_Poll(void) { if(!mouseTrapped) { // We are not supposed to be reading the mouse right now. return; } // Try to get the mouse state. int tries = 1; BOOL acquired = false; while(!acquired && tries > 0) { HRESULT hr = didMouse->GetDeviceState(sizeof(mstate), &mstate); if(SUCCEEDED(hr)) { acquired = true; } else if(tries > 0) { // Try to reacquire. didMouse->Acquire(); tries--; } } if(!acquired) { // The operation is a failure. memset(&mstate, 0, sizeof(mstate)); } }
//----------------------------------------------------------- HRESULT UpdateMouse() { HRESULT result; // 前回の値保存 DIMOUSESTATE2 lastMouseState = mouseState; // データ取得 result = pMouse->GetDeviceState(sizeof(mouseState),&mouseState); if(SUCCEEDED(result)) { mouseTrigger.lX = mouseState.lX; mouseTrigger.lY = mouseState.lY; mouseTrigger.lZ = mouseState.lZ; // マウスのボタン状態 for(int i=0;i<8;i++) { mouseTrigger.rgbButtons[i] = ((lastMouseState.rgbButtons[i] ^ mouseState.rgbButtons[i]) & mouseState.rgbButtons[i]); } } else // 取得失敗 { // アクセス権を得てみる result = pMouse->Acquire(); } return result; }
void getKeyStates( const unsigned char numKeys, const unsigned short* keys, unsigned char* states, unsigned char* modifierMask ) { static BYTE keystate[MAX_KEYS]; // create a static storage for the key-states dinKeyboard->Acquire(); // get access if we don't have it already dinKeyboard->GetDeviceState( MAX_KEYS, (LPVOID)keystate ); // fill keystate with values *modifierMask = 0; if ( keystate[DIK_LSHIFT] & 0x80 ) *modifierMask |= MODIFIER_MASK_SHIFT; if ( keystate[DIK_RSHIFT] & 0x80 ) *modifierMask |= MODIFIER_MASK_SHIFT; if ( keystate[DIK_LCONTROL] & 0x80 ) *modifierMask |= MODIFIER_MASK_CTRL; if ( keystate[DIK_RCONTROL] & 0x80 ) *modifierMask |= MODIFIER_MASK_CTRL; if ( keystate[DIK_LMENU] & 0x80 ) *modifierMask |= MODIFIER_MASK_LALT; if ( keystate[DIK_RMENU] & 0x80 ) *modifierMask |= MODIFIER_MASK_RALT; if ( keystate[DIK_LMENU] & 0x80 ) *modifierMask |= MODIFIER_MASK_LMETA; if ( keystate[DIK_RMENU] & 0x80 ) *modifierMask |= MODIFIER_MASK_RMETA; for ( unsigned short i = 0; i < numKeys; i++ ) { states[i] = ( keystate[keys[i]] & 0x80 ) ? 1 : 0; } }
//----------------------------------------------------------------------------- // Name: UpdateInputState() // Desc: Get the input device's state and display it. //----------------------------------------------------------------------------- HRESULT UpdateInputState() { HRESULT hr; DIJOYSTATE2 js; // DInput joystick state state.is_valid = false; if (!g_pJoystick) { state.message = "No device at index"; return S_OK; } // Poll the device to read the current state hr = g_pJoystick->Poll(); if (FAILED(hr)) { state.message = "device stream interrupted"; // DInput is telling us that the input stream has been // interrupted. We aren't tracking any state between polls, so // we don't have any special reset that needs to be done. We // just re-acquire and try again. hr = g_pJoystick->Acquire(); //while (hr == DIERR_INPUTLOST) // hr = g_pJoystick->Acquire(); // hr may be DIERR_OTHERAPPHASPRIO or other errors. This // may occur when the app is minimized or in the process of // switching, so just try again later return S_OK; } // Get the input's device state if (FAILED(hr = g_pJoystick->GetDeviceState(sizeof(DIJOYSTATE2), &js))) { state.message = "GetDeviceState failed"; return hr; // The device should have been acquired during the Poll() } state.is_valid = true; state.message = ""; // Axes state.x = js.lX; state.y = js.lY; state.z = js.lZ; state.rx = js.lRx; state.ry = js.lRy; state.rz = js.lRz; state.slider0 = js.rglSlider[0]; state.slider1 = js.rglSlider[1]; // Slider controls state.slider0 = js.rglSlider[0]; state.slider1 = js.rglSlider[1]; // Points of view state.pov0 = js.rgdwPOV[0]; state.pov1 = js.rgdwPOV[1]; state.pov2 = js.rgdwPOV[2]; state.pov3 = js.rgdwPOV[3]; // Buttons for (int i = 0; i < 128; i++) { state.buttons[i] = js.rgbButtons[i]; } return S_OK; }
void processInput() { // Gestion du clavier char buffer[256]; if(FAILED(g_pKeyboardDevice->GetDeviceState(sizeof(buffer), (LPVOID)&buffer))) return; if(buffer[DIK_ESCAPE] & 0x80) PostQuitMessage(0); if(buffer[DIK_UP] & 0x80) { g_CameraX += CAMERA_SPEED*sin(g_Theta)*sin(g_Phi); g_CameraY += CAMERA_SPEED*cos(g_Theta); g_CameraZ += CAMERA_SPEED*sin(g_Theta)*cos(g_Phi); } else if(buffer[DIK_DOWN] & 0x80) { g_CameraX -= CAMERA_SPEED*sin(g_Theta)*sin(g_Phi); g_CameraY -= CAMERA_SPEED*cos(g_Theta); g_CameraZ -= CAMERA_SPEED*sin(g_Theta)*cos(g_Phi); } if(buffer[DIK_RIGHT] & 0x80) { g_CameraX -= CAMERA_SPEED*cos(g_Phi); g_CameraZ += CAMERA_SPEED*sin(g_Phi); } else if(buffer[DIK_LEFT] & 0x80) { g_CameraX += CAMERA_SPEED*cos(g_Phi); g_CameraZ -= CAMERA_SPEED*sin(g_Phi); } // Gestion de la souris DIMOUSESTATE state; if(FAILED(g_pMouseDevice->GetDeviceState(sizeof(state), (LPVOID)&state))) return; g_Phi -= state.lX*MOUSE_SENSITIVITY; g_Theta += state.lY*MOUSE_SENSITIVITY; if(g_Phi < 0.0f) g_Phi += 2.0f*PI; else if(g_Phi >= 2.0f*PI) g_Phi -= 2.0f*PI; if(g_Theta < 0.0f) g_Theta = 0.0f; else if(g_Theta > PI) g_Theta = PI; }
//----------------------------------------------------------------------------- // Name: ReadImmediateData() // Desc: Read the input device's state when in immediate mode and display it. //----------------------------------------------------------------------------- HRESULT ReadImmediateData( HWND hDlg ) { HRESULT hr; TCHAR strNewText[128] = TEXT(""); // Output string DIMOUSESTATE2 dims2; // DirectInput mouse state structure if( NULL == g_pMouse ) return S_OK; // Get the input's device state, and put the state in dims ZeroMemory( &dims2, sizeof(dims2) ); hr = g_pMouse->GetDeviceState( sizeof(DIMOUSESTATE2), &dims2 ); if( FAILED(hr) ) { // DirectInput may be telling us that the input stream has been // interrupted. We aren't tracking any state between polls, so // we don't have any special reset that needs to be done. // We just re-acquire and try again. // If input is lost then acquire and keep trying hr = g_pMouse->Acquire(); while( hr == DIERR_INPUTLOST ) hr = g_pMouse->Acquire(); // Update the dialog text if( hr == DIERR_OTHERAPPHASPRIO || hr == DIERR_NOTACQUIRED ) SetDlgItemText( hDlg, IDC_DATA, TEXT("Unacquired") ); // hr may be DIERR_OTHERAPPHASPRIO or other errors. This // may occur when the app is minimized or in the process of // switching, so just try again later return S_OK; } // The dims structure now has the state of the mouse, so // display mouse coordinates (x, y, z) and buttons. _stprintf( strNewText, TEXT("(X=% 3.3d, Y=% 3.3d, Z=% 3.3d) B0=%c B1=%c B2=%c B3=%c B4=%c B5=%c B6=%c B7=%c"), dims2.lX, dims2.lY, dims2.lZ, (dims2.rgbButtons[0] & 0x80) ? '1' : '0', (dims2.rgbButtons[1] & 0x80) ? '1' : '0', (dims2.rgbButtons[2] & 0x80) ? '1' : '0', (dims2.rgbButtons[3] & 0x80) ? '1' : '0', (dims2.rgbButtons[4] & 0x80) ? '1' : '0', (dims2.rgbButtons[5] & 0x80) ? '1' : '0', (dims2.rgbButtons[6] & 0x80) ? '1' : '0', (dims2.rgbButtons[7] & 0x80) ? '1' : '0'); // Get the old text in the text box TCHAR strOldText[128]; GetDlgItemText( hDlg, IDC_DATA, strOldText, 127 ); // If nothing changed then don't repaint - avoid flicker if( 0 != lstrcmp( strOldText, strNewText ) ) SetDlgItemText( hDlg, IDC_DATA, strNewText ); return S_OK; }
//============================================================================= // キーボードの更新処理 //============================================================================= HRESULT UpdateKeyboard(void) { HRESULT hr; BYTE aKeyState[NUM_KEY_MAX]; // デバイスからデータを取得 hr = g_pDIDevKeyboard->GetDeviceState(sizeof(aKeyState), aKeyState); if(SUCCEEDED(hr)) { for(int nCntKey = 0; nCntKey < NUM_KEY_MAX; nCntKey++) { g_aKeyStateTrigger[nCntKey] = (g_aKeyState[nCntKey] ^ aKeyState[nCntKey]) & aKeyState[nCntKey]; g_aKeyStateRelease[nCntKey] = (g_aKeyState[nCntKey] ^ aKeyState[nCntKey]) & ~aKeyState[nCntKey]; if(aKeyState[nCntKey]) { g_aKeyStateRepeatCnt[nCntKey]++; if(g_aKeyStateRepeatCnt[nCntKey] < g_nCountWaitRepeat) { if(g_aKeyStateRepeatCnt[nCntKey] == 1 || g_aKeyStateRepeatCnt[nCntKey] >= g_nCountWaitRepeat) { g_aKeyStateRepeat[nCntKey] = aKeyState[nCntKey]; } else { g_aKeyStateRepeat[nCntKey] = 0; } } else { if(((g_aKeyStateRepeatCnt[nCntKey] - g_nCountWaitRepeat) % g_nIntervalRepeat) == 0) { g_aKeyStateRepeat[nCntKey] = aKeyState[nCntKey]; } else { g_aKeyStateRepeat[nCntKey] = 0; } } } else { g_aKeyStateRepeatCnt[nCntKey] = 0; g_aKeyStateRepeat[nCntKey] = 0; } g_aKeyState[nCntKey] = aKeyState[nCntKey]; } } else { // キーボードへのアクセス権を取得 g_pDIDevKeyboard->Acquire(); } return S_OK; }
const char *GetKeyState() { HRESULT hr = g_pDIDevice->Acquire(); if ((hr==DI_OK)||(hr==S_FALSE)) { g_pDIDevice->GetDeviceState(sizeof(g_keys), &g_keys); return g_keys; } return NULL; }
/** ** DirectInput update **/ void DirectInput_Update() { //update mouse dimouse->GetDeviceState(sizeof(mouse_state), (LPVOID)&mouse_state); //update keyboard dikeyboard->GetDeviceState(sizeof(keys), (LPVOID)&keys); //update controllers for (int i=0; i< 4; i++ ) { ZeroMemory( &controllers[i], sizeof(XINPUT_STATE) ); //get the state of the controller XINPUT_STATE state; DWORD result = XInputGetState( i, &state ); //store state in global controllers array if (result == 0) controllers[i] = state.Gamepad; } }
/* Update joystick status */ BOOL JoystickUpdate (void) { /* Poll the joystick */ if (FAILED (m_lpkDIDevice->Poll ()) ) { /* Acquire joystick */ HRESULT hRet = m_lpkDIDevice->Acquire (); if ((FAILED (hRet)) && (hRet == DIERR_INPUTLOST)) { m_lpkDIDevice->Acquire (); } else { return FALSE; } } if(JOY) { /* Get device data */ if (FAILED (m_lpkDIDevice->GetDeviceState (sizeof (DIJOYSTATE2), &m_kDeviceData)) ) { return FALSE; } } else { if (FAILED (m_lpkDIDevice->GetDeviceState (sizeof (m_strKeyState), &m_strKeyState)) ) { return FALSE; } } return TRUE; }
m64p_error VidExt_GL_SwapBuffers() { CMupen64Plus* instance = CMupen64Plus::GetSingleton( ) ; SwapBuffers( g_hDC ); BYTE keys[256]; build_keymap(); // Get the input's device state, and put the state in keys - zero first ZeroMemory(keys, sizeof(keys) ); HRESULT result = m_pDIKeyboardDevice->GetDeviceState( sizeof(keys), keys ); if ( (result == DIERR_INPUTLOST) || (result == DIERR_NOTACQUIRED) ) { m_pDIKeyboardDevice->Acquire(); m_pDIKeyboardDevice->Poll(); m_pDIKeyboardDevice->GetDeviceState( sizeof(keys), keys ); } for(int i=0;i<256;i++) { if(keys[i] & 0x80) { SDL_keysym keysym; SDL_keysym *pressed =TranslateKey(i,&keysym,0); instance->CoreDoCommand(M64CMD_SEND_SDL_KEYDOWN,MAKELPARAM(pressed->sym,0), NULL); } else { SDL_keysym keysym; SDL_keysym *pressed =TranslateKey(i,&keysym,0); instance->CoreDoCommand(M64CMD_SEND_SDL_KEYUP,MAKELPARAM(pressed->sym,0), NULL); } } return M64ERR_SUCCESS; }
bool OutDevice::Read(LPDIRECTINPUTDEVICE8 dev,void* pBuffer, long lSize) { HRESULT hr; while(true) { dev->Poll(); //轮询 dev->Acquire(); //获取设备控制权 if(SUCCEEDED(hr=dev->GetDeviceState(lSize,pBuffer))) break; if(hr != DIERR_INPUTLOST || hr != DIERR_NOTACQUIRED) return false; if(FAILED(dev->Acquire())) return false; } return true; }
HRESULT poll(LPDIRECTINPUTDEVICE8 joystick, LPDIJOYSTATE2 js) { // Device polling (as seen on x360ce) HRESULT hr = E_FAIL; if (!joystick) return E_FAIL; joystick->Poll(); hr = joystick->GetDeviceState(sizeof(DIJOYSTATE2), js); if (FAILED(hr)) { // Reacquire the device (only once) hr = joystick->Acquire(); } return hr; }
void WINAPI DICreateMouseDevice(HANDLE window) { traceIn(DICreateMouseDevice); if(bDInputActive) { HRESULT result; if(diDevice->CreateDevice(GUID_SysMouse, &diMouse, NULL) != DI_OK) CrashError(TEXT("DInput: Could not Create Mouse device")); if(diMouse->SetDataFormat(&c_dfDIMouse) != DI_OK) CrashError(TEXT("DInput: Could not set mouse data format")); if(diMouse->SetCooperativeLevel((HWND)window, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE) != DI_OK) CrashError(TEXT("DInput: Could not set mouse cooperation level")); if((result = diMouse->SetEventNotification(InputEvents[1])) != DI_OK) CrashError(TEXT("DInput: couldn't set a mouse notification. that sucks.")); if((result = diMouse->Acquire()) != DI_OK) { if(result != DIERR_OTHERAPPHASPRIO) CrashError(TEXT("DInput: Could not aquire mouse device")); } if((result = diMouse->GetDeviceState(sizeof(DIMOUSESTATE), &mousestate)) != DI_OK) { if((result != DIERR_OTHERAPPHASPRIO) && (result != DIERR_NOTACQUIRED)) CrashError(TEXT("DInput: Could not get mouse state")); curMouseButtonStates = 0; } else { if(mousestate.rgbButtons[0]) curMouseButtonStates |= STATE_LBUTTONDOWN; if(mousestate.rgbButtons[1]) curMouseButtonStates |= STATE_MBUTTONDOWN; if(mousestate.rgbButtons[2]) curMouseButtonStates |= STATE_RBUTTONDOWN; } } traceOut; }
void WINAPI DICreateKeyboardDevice(HANDLE window) { traceIn(DICreateKeyboardDevice); if(bDInputActive) { HRESULT result; if(diDevice->CreateDevice(GUID_SysKeyboard, &diKeyboard, NULL) != DI_OK) CrashError(TEXT("DInput: Could not Create Keyboard device")); if(diKeyboard->SetDataFormat(&c_dfDIKeyboard) != DI_OK) CrashError(TEXT("DInput: Could not set keyboard data format")); if(diKeyboard->SetCooperativeLevel((HWND)window, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE) != DI_OK) CrashError(TEXT("DInput: Could not set keyboard cooperation level")); if((result = diKeyboard->SetEventNotification(InputEvents[0])) != DI_OK) CrashError(TEXT("DInput: couldn't set a keyboard notification. that sucks.")); if((result = diKeyboard->Acquire()) != DI_OK) { if(result != DIERR_OTHERAPPHASPRIO) CrashError(TEXT("DInput: Could not aquire keyboard device")); } if((result = diKeyboard->GetDeviceState(256, keys)) != DI_OK) { if((result != DIERR_OTHERAPPHASPRIO) && (result != DIERR_NOTACQUIRED)) CrashError(TEXT("DInput: Could not get keyboard device state")); } /*else { keys[DIK_LSHIFT] |= keys[DIK_RSHIFT]; keys[DIK_RSHIFT] = 0; keys[DIK_LCONTROL] |= keys[DIK_RCONTROL]; keys[DIK_RCONTROL] = 0; }*/ } traceOut; }
//============================================================================= // キーボードの更新処理 //============================================================================= void UpdateKeyboard(void) { BYTE aKeyState[NUM_KEY_MAX]; // デバイスからデータを取得 if(SUCCEEDED(g_pDevKeyboard->GetDeviceState(sizeof(aKeyState), aKeyState))) { for(int nCnKey = 0; nCnKey < NUM_KEY_MAX; nCnKey++) { g_aKeyStateTrigger[nCnKey] = (g_aKeyState[nCnKey] ^ aKeyState[nCnKey]) & aKeyState[nCnKey]; g_aKeyStateRelease[nCnKey] = (g_aKeyState[nCnKey] ^ aKeyState[nCnKey]) & ~aKeyState[nCnKey]; if(aKeyState[nCnKey]) { if(g_aKeyStateRepeatCnt[nCnKey] < LIMIT_COUNT_REPEAT) { g_aKeyStateRepeatCnt[nCnKey]++; if(g_aKeyStateRepeatCnt[nCnKey] == 1 || g_aKeyStateRepeatCnt[nCnKey] >= LIMIT_COUNT_REPEAT) { g_aKeyStateRepeat[nCnKey] = aKeyState[nCnKey]; } else { g_aKeyStateRepeat[nCnKey] = 0; } } } else { g_aKeyStateRepeatCnt[nCnKey] = 0; g_aKeyStateRepeat[nCnKey] = 0; } g_aKeyState[nCnKey] = aKeyState[nCnKey]; } } else { // キーボードへのアクセス権を取得 g_pDevKeyboard->Acquire(); } }
void CG27::run() { HRESULT hr; if (g_pJoystick == NULL) { return; } while(1) { hr = g_pJoystick->Poll(); g_pJoystick->Acquire(); g_mutexG27.lock(); hr = g_pJoystick->GetDeviceState( sizeof( DIJOYSTATE2 ), &g_G27State); emit(GetG27Info()); qDebug() << g_G27State.lX; /* qDebug() << g_G27State.lY; qDebug() << g_G27State.lZ; qDebug() << g_G27State.lRx; qDebug() << g_G27State.lRy; qDebug() << g_G27State.lRz; qDebug() << g_G27State.lVX; qDebug() << g_G27State.lVY; qDebug() << g_G27State.lVZ; qDebug() << g_G27State.lAX; qDebug() << g_G27State.lAY; qDebug() << g_G27State.lAZ; qDebug() << " "; */ qDebug() << " "; qDebug() << " "; g_mutexG27.unlock(); usleep(5000); } return; }
int GutReadKeyboard(char buffer[256]) { if ( NULL == g_pKeyboard ) return 0; int hr = g_pKeyboard->GetDeviceState( 256, buffer ); if ( FAILED(hr) ) { hr = g_pKeyboard->Acquire(); for(int i=0; hr == DIERR_INPUTLOST && i<10; i++ ) { hr = g_pKeyboard->Acquire(); if ( !FAILED(hr) ) break; } memset(buffer, 0, 256); return 0; } return 1; }
int GutReadJoystick(GutJoystickInfo *joystick) { DIJOYSTATE js; if ( g_pJoystick==NULL || joystick==NULL ) return 0; // Poll the device to read the current state int hr = g_pJoystick->Poll(); if( FAILED(hr) ) { g_pJoystick->Acquire(); g_pJoystick->Poll(); } // Get the input's device state hr = g_pJoystick->GetDeviceState( sizeof(DIJOYSTATE), &js ); if( hr == DIERR_INPUTLOST ) { // DInput is telling us that the input stream has been // interrupted. We aren't tracking any state between polls, so // we don't have any special reset that needs to be done. We // just re-acquire and try again. hr = g_pJoystick->Acquire(); if( FAILED(hr) ) return 0; } joystick->x = js.lX; joystick->y = js.lY; joystick->z = js.lZ; joystick->rx = js.lRx; joystick->ry = js.lRy; joystick->rz = js.lRz; joystick->pov[0] = js.rgdwPOV[0]; joystick->pov[1] = js.rgdwPOV[1]; joystick->pov[2] = js.rgdwPOV[2]; joystick->pov[3] = js.rgdwPOV[3]; memcpy(joystick->button, js.rgbButtons, 32); return 1; }
//============================================================================= // キーボードの更新 //============================================================================= HRESULT UpdateKeyboard(void) { HRESULT hr; BYTE keyStateOld[256]; // 前回のデータを保存 memcpy(keyStateOld, g_keyState, NUM_KEY_MAX); // デバイスからデータを取得 hr = g_pDIDevKeyboard->GetDeviceState(sizeof(g_keyState), g_keyState); if(SUCCEEDED(hr)) { for(int cnt = 0; cnt < NUM_KEY_MAX; cnt++) { g_keyStateTrigger[cnt] = (keyStateOld[cnt] ^ g_keyState[cnt]) & g_keyState[cnt]; g_keyStateRelease[cnt] = (keyStateOld[cnt] ^ g_keyState[cnt]) & ~g_keyState[cnt]; g_keyStateRepeat[cnt] = g_keyStateTrigger[cnt]; if(g_keyState[cnt]) { g_keyStateRepeatCnt[cnt]++; if(g_keyStateRepeatCnt[cnt] >= 20) { g_keyStateRepeat[cnt] = g_keyState[cnt]; } } else { g_keyStateRepeatCnt[cnt] = 0; g_keyStateRepeat[cnt] = 0; } } } else { // キーボードへのアクセス権を取得 g_pDIDevKeyboard->Acquire(); } return S_OK; }
int DInput_Read_Keyboard(void) { // this function reads the state of the keyboard if (lpdikey) { if (lpdikey->GetDeviceState(256, (LPVOID)keyboard_state)!=DI_OK) return(0); } else { // keyboard isn't plugged in, zero out state memset(keyboard_state,0,sizeof(keyboard_state)); // return error return(0); } // end else // return sucess return(1); } // end DInput_Read_Keyboard
int DInput_Read_Mouse(void) { // this function reads the mouse state if (lpdimouse) { if (lpdimouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&mouse_state)!=DI_OK) return(0); } else { // mouse isn't plugged in, zero out state memset(&mouse_state,0,sizeof(mouse_state)); // return error return(0); } // end else // return sucess return(1); } // end DInput_Read_Mouse
// Update, polls values from Joystick bool JoystickHandler::update() { for(int iEntry = 0; iEntry < nEntry; ++iEntry) { Entry& e = entry[iEntry]; LPDIRECTINPUTDEVICE8 d = e.diDevice; if(FAILED(d->Poll())) { HRESULT hr = d->Acquire(); while(hr == DIERR_INPUTLOST) { hr = d->Acquire(); } } else { d->GetDeviceState(sizeof(DIJOYSTATE2), &e.joystate); } } const JoystickHandler::Entry* e = this->getEntry(0); if(e) { this->js = &e->joystate; return true; } return false; }
void Poll_Keyboard_DInput() { HRESULT hr; if( !di_keyboard ) return; // creates poll errors //memset( keyboard_state[0], 0, sizeof(keyboard_state[0]) ); //memset( keyboard_state[1], 0, sizeof(keyboard_state[1]) ); // assume lost input (alt-tab) hr = DIERR_INPUTLOST; while( hr == DIERR_INPUTLOST ) hr = di_keyboard->Acquire(); if( FAILED(hr) ) return; di_keyboard->GetDeviceState( 256, (LPVOID)di_keystate ); }