Bug in wxJoystickEvent?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
User avatar
zoxks
Earned a small fee
Earned a small fee
Posts: 10
Joined: Tue Apr 27, 2021 11:38 pm

Bug in wxJoystickEvent?

Post by zoxks »

I have two identical joysticks (both Thrustmaster T.16000M), and I'm trying to listen for events for both of them. I'm capturing the events like such:

Code: Select all

void JoystickController::OnJoystickEvent(wxJoystickEvent& event) {

    //Get id of changed stick and index it from 0
    int stickId = event.GetJoystick();
    cout << "stickId:  " << stickId << "\n";
    cout << "ONE: " << wxJOYSTICK1 << "\n";
    cout << "TWO: " << wxJOYSTICK2 << "\n";
}
When I get the stick ID, it comes out as either 1, or 2 (pressing a button on the left and right sticks):

Code: Select all

stickId:  1
ONE: 0
TWO: 1
stickId:  2
ONE: 0
TWO: 1
However the documentation here states that GetJoystick will return:
Returns the identifier of the joystick generating the event - one of wxJOYSTICK1 and wxJOYSTICK2.
On a separate computer, the value of GetJoystick is indeed 0, and 1. What is causing this?
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Bug in wxJoystickEvent?

Post by doublemax »

Platform, wxWidgets version?

What does wxJoystick::GetNumberJoysticks() return?
Use the source, Luke!
User avatar
zoxks
Earned a small fee
Earned a small fee
Posts: 10
Joined: Tue Apr 27, 2021 11:38 pm

Re: Bug in wxJoystickEvent?

Post by zoxks »

Sorry :oops: . Windows 10, WX 3.1.5
wxJoystick::GetNumberJoysticks() returns 2
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Bug in wxJoystickEvent?

Post by PB »

I have never used wxJoystickEvent nor am I familiar with handling game controller input.

Be that as it may, to me it seems that the documentation is incorrect.

Firstly, that returning one of the two wxJOYSTICKn values would mean that a system can have only at most two game controllers attached (I suppose that includes gamepads and similar): Is that true?

Secondly, looking at the source code, AFAICT the joystick id (m_joystick) on MSW is assigned like this, which means it can be an arbitrary number.
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Bug in wxJoystickEvent?

Post by doublemax »

Can you trace through wxJoystick::GetNumberJoysticks() with a debugger? I suspect that for some reason your system has 3 joystick devices, with the first being invalid, so that number is skipped.
Use the source, Luke!
Post Reply