1

Scenario: I have written some basic controlling programm for my quadcopter. Basically, I use a notebook with a gamepad connected to it to send commands to my quadcopter, both are connected to each other via radio. This setups works suprisingly well, but:

Question: How can my Win32 application that runs on my notebook receive gamepad state changes even if the window is not in focus? I know that some programs like AutoHotKey and AutoIt provide exactly that, but I couldn't find any documentation, neither in the official XInput documentation nor in the internet.

The problem is, that I sometimes also use ArduPilot's Mission Planner software simutaneously on the same notebook. So everytime I want to look some telemetry data up in Mission Planer, the application window handling the gamepad stuff goes out of focus, and it stops receiving gamepad state changes, which is very annoying, and, to be honest, also kind of dangerous, because I should have a working radio controll at all times.

So, Is there a way to "lock" gamepad XInput to a particular window handle? The (Win32) application is written in C++ with Visual Studio.

EDIT: I use the native XInput API hence I use XInputGetState(). My Message loop is designed to poll XInputGetState() everytime there is no Message to Translate-/DispatchMessage(), and the WinMessages are polled with the non-blocking PeekMessage().

luksen
  • 67
  • 5
  • How are you receiving gamepad state changes? Are you using XInputGetState to retrieve your gamepad state or some other method or library? Are you continuing to call XInputGetState() every frame even after your window has lost focus? XInputGetState() should return valid gamepad state regardless of whether your window has focus or not. – Chip Burwell Oct 11 '15 at 22:25
  • Yes, I use the native XInput API hence I use XInputGetState(). My Message loop is designed to poll XInputGetState() everytime there is no Message to Translate-/DispatchMessage(), and the WinMessages are polled with the non-blocking PeekMessage(). I added this information to my initial question. – luksen Oct 12 '15 at 13:54
  • BTW: My application is not completely unactive, only the gamepad stuff is. I know this because I send some kind of a "heartbeat" message to the quadcopter as a means for knowing if the application is sending correctly. If the "packet rate" of these "heartbeat" messages undercut a specific threshold or one "heartbeat" message is send significantly to late, the quadcopter takes some precautionary measure, basically auto-landing, and this still works even if the window is unfocused. – luksen Oct 12 '15 at 14:48
  • If you are calling XinputGetState() regularly you should be receiving gamepad input. Verify that XInputGetState is being called and that your event loop isn't getting stuck. If you are indeed calling XInputGetState regularly it should be returning gamepad state correctly regardless of window focus. – Chip Burwell Oct 12 '15 at 17:56

0 Answers0