mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-07-11 01:25:07 +02:00
Release all buttons and axes on DInput device disconnection
This commit is contained in:
@@ -174,6 +174,7 @@ DinputDevice::DinputDevice(int devnum) {
|
||||
|
||||
DinputDevice::~DinputDevice() {
|
||||
KeyMap::NotifyPadDisconnected(DEVICE_ID_PAD_0 + pDevNum);
|
||||
ReleaseAllKeys();
|
||||
|
||||
if (pJoystick) {
|
||||
pJoystick = nullptr;
|
||||
@@ -190,6 +191,48 @@ DinputDevice::~DinputDevice() {
|
||||
}
|
||||
}
|
||||
|
||||
void DinputDevice::ReleaseAllKeys() {
|
||||
KeyInput key;
|
||||
key.deviceId = DEVICE_ID_PAD_0 + pDevNum;
|
||||
key.flags = KeyInputFlags::UP;
|
||||
for (int i = 0; i < ARRAY_SIZE(dinput_buttons); ++i) {
|
||||
if (lastButtons_[i] != 0) {
|
||||
key.keyCode = dinput_buttons[i];
|
||||
NativeKey(key);
|
||||
lastButtons_[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Release DPad
|
||||
static const InputKeyCode dpadCodes[] = {
|
||||
NKCODE_DPAD_UP,
|
||||
NKCODE_DPAD_DOWN,
|
||||
NKCODE_DPAD_LEFT,
|
||||
NKCODE_DPAD_RIGHT
|
||||
};
|
||||
for (int i = 0; i < ARRAY_SIZE(dpadCodes); ++i) {
|
||||
key.keyCode = dpadCodes[i];
|
||||
NativeKey(key);
|
||||
}
|
||||
|
||||
// Release axes
|
||||
static const InputAxis axes[] = {
|
||||
JOYSTICK_AXIS_X,
|
||||
JOYSTICK_AXIS_Y,
|
||||
JOYSTICK_AXIS_Z,
|
||||
JOYSTICK_AXIS_RX,
|
||||
JOYSTICK_AXIS_RY,
|
||||
JOYSTICK_AXIS_RZ
|
||||
};
|
||||
for (int i = 0; i < ARRAY_SIZE(axes); ++i) {
|
||||
AxisInput axis;
|
||||
axis.deviceId = DEVICE_ID_PAD_0 + pDevNum;
|
||||
axis.axisId = axes[i];
|
||||
axis.value = 0.0f;
|
||||
NativeAxis(&axis, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void SendNativeAxis(InputDeviceID deviceId, int value, int &lastValue, InputAxis axisId) {
|
||||
if (value != lastValue) {
|
||||
AxisInput axis;
|
||||
|
||||
@@ -45,6 +45,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
void ReleaseAllKeys();
|
||||
void ApplyButtons(DIJOYSTATE2 &state);
|
||||
//unfortunate and unclean way to keep only one DirectInput instance around
|
||||
static LPDIRECTINPUT8 getPDI();
|
||||
|
||||
Reference in New Issue
Block a user