jkuhlmann / gainput

Cross-platform C++ input library supporting gamepads, keyboard, mouse, touch
http://gainput.johanneskuhlmann.de/
MIT License
858 stars 103 forks source link

Can't differentiate multiple gamepad inputs on macOS #58

Open ShamylZakariya opened 6 years ago

ShamylZakariya commented 6 years ago

I connect two PS4 controllers to my mac (10.13) and create two gainput::InputDevicePad instances.

_gamepads.push_back(_inputManager->CreateDevice<gainput::InputDevicePad>());
_gamepads.push_back(_inputManager->CreateDevice<gainput::InputDevicePad>());

In a polling loop I print the state of the left and right analog sticks for the two devices.

auto device1 = _inputManager->GetDevice(_gamepads[0]);
auto device2 = _inputManager->GetDevice(_gamepads[1]);

vec2 leftStick1(device1->GetFloat(gainput::PadButtonLeftStickX),device1->GetFloat(gainput::PadButtonLeftStickY));
vec2 rightStick1(device1->GetFloat(gainput::PadButtonRightStickX),device1->GetFloat(gainput::PadButtonRightStickY));
vec2 leftStick2(device2->GetFloat(gainput::PadButtonLeftStickX),device2->GetFloat(gainput::PadButtonLeftStickY));
vec2 rightStick2(device2->GetFloat(gainput::PadButtonRightStickX),device2->GetFloat(gainput::PadButtonRightStickY));

cout << "leftStick1: " << leftStick1 << " rightStick1:" << rightStick1 << endl;
cout << "leftStick2: " << leftStick2 << " rightStick2:" << rightStick2 << endl << endl;

If I move the analog sticks on either gamepad 1 or 2, I see its position reflected in both device1 and device2.

gainput is, I guess, merging the state of the two controllers.

Am I creating the devices incorrectly?