Пример #1
0
extern s32 __stdcall GetControllerInput(s32 port)
{
	for(int i = 0; i < 100; i++)
	{	
		XINPUT_STATE state;
		DWORD result = DuraznoGetState(port, &state);
	
		if(result != ERROR_SUCCESS) return -1;

		if(GetAsyncKeyState(VK_DELETE)) return Gamepad::DISABLED;
	
		if(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP)    return Gamepad::DPAD_UP;
		if(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN)  return Gamepad::DPAD_DOWN;
		if(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT)  return Gamepad::DPAD_LEFT;
		if(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT) return Gamepad::DPAD_RIGHT;

		if(state.Gamepad.wButtons & XINPUT_GAMEPAD_START) return Gamepad::START;
		if(state.Gamepad.wButtons & XINPUT_GAMEPAD_BACK)  return Gamepad::BACK;

		if(state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB)  return Gamepad::LEFT_THUMB;
		if(state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB) return Gamepad::RIGHT_THUMB;

		if(state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER) return Gamepad::LEFT_SHOULDER;
		if(state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER) return Gamepad::RIGHT_SHOULDER;

		if(state.Gamepad.wButtons & XINPUT_GAMEPAD_A) return Gamepad::A;
		if(state.Gamepad.wButtons & XINPUT_GAMEPAD_B) return Gamepad::B;
		if(state.Gamepad.wButtons & XINPUT_GAMEPAD_X) return Gamepad::X;
		if(state.Gamepad.wButtons & XINPUT_GAMEPAD_Y) return Gamepad::Y;

		s32 threshold = 100;

		if(state.Gamepad.bLeftTrigger  > threshold) return Gamepad::LEFT_TRIGGER;
		if(state.Gamepad.bRightTrigger > threshold) return Gamepad::RIGHT_TRIGGER;
	
		threshold = 16384;

		if(state.Gamepad.sThumbLX >  threshold) return Gamepad::THUMB_LX_P;
		if(state.Gamepad.sThumbLX < -threshold) return Gamepad::THUMB_LX_M;
		if(state.Gamepad.sThumbLY >  threshold) return Gamepad::THUMB_LY_P;
		if(state.Gamepad.sThumbLY < -threshold) return Gamepad::THUMB_LY_M;

		if(state.Gamepad.sThumbRX >  threshold) return Gamepad::THUMB_RX_P;
		if(state.Gamepad.sThumbRX < -threshold) return Gamepad::THUMB_RX_M;
		if(state.Gamepad.sThumbRY >  threshold) return Gamepad::THUMB_RY_P;
		if(state.Gamepad.sThumbRY < -threshold) return Gamepad::THUMB_RY_M;

		Sleep(100);
	}

	return -1;
}
Пример #2
0
DWORD WINAPI GetControllerInput(DWORD port)
{
	XINPUT_STATE state;
	int i;

	for (i = 0; i < 100; i++)
	{
		if (DuraznoGetState(port, &state) != ERROR_SUCCESS)
			return (DWORD)-1;

		if (GetAsyncKeyState(VK_DELETE)) return CTRL_DISABLED;

		if (state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP)    return CTRL_DPAD_UP;
		if (state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN)  return CTRL_DPAD_DOWN;
		if (state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT)  return CTRL_DPAD_LEFT;
		if (state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT) return CTRL_DPAD_RIGHT;

		if (state.Gamepad.wButtons & XINPUT_GAMEPAD_START) return CTRL_START;
		if (state.Gamepad.wButtons & XINPUT_GAMEPAD_BACK)  return CTRL_BACK;

		if (state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB)  return CTRL_LEFT_THUMB;
		if (state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB) return CTRL_RIGHT_THUMB;

		if (state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER)  return CTRL_LEFT_SHOULDER;
		if (state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER) return CTRL_RIGHT_SHOULDER;

		if (state.Gamepad.wButtons & XINPUT_GAMEPAD_A) return CTRL_A;
		if (state.Gamepad.wButtons & XINPUT_GAMEPAD_B) return CTRL_B;
		if (state.Gamepad.wButtons & XINPUT_GAMEPAD_X) return CTRL_X;
		if (state.Gamepad.wButtons & XINPUT_GAMEPAD_Y) return CTRL_Y;

		if (state.Gamepad.bLeftTrigger  > 100) return CTRL_LEFT_TRIGGER;
		if (state.Gamepad.bRightTrigger > 100) return CTRL_RIGHT_TRIGGER;

		if (state.Gamepad.sThumbLX >  16000) return CTRL_THUMB_LX_P;
		if (state.Gamepad.sThumbLX < -16000) return CTRL_THUMB_LX_N;
		if (state.Gamepad.sThumbLY >  16000) return CTRL_THUMB_LY_P;
		if (state.Gamepad.sThumbLY < -16000) return CTRL_THUMB_LY_N;

		if (state.Gamepad.sThumbRX >  16000) return CTRL_THUMB_RX_P;
		if (state.Gamepad.sThumbRX < -16000) return CTRL_THUMB_RX_N;
		if (state.Gamepad.sThumbRY >  16000) return CTRL_THUMB_RY_P;
		if (state.Gamepad.sThumbRY < -16000) return CTRL_THUMB_RY_N;

		Sleep(100);
	}

	return (DWORD)-1;
}