tags:

views:

65

answers:

2

I am using joySetCapture with fChanged (4'th parameter) = true.

I am getting the messages only when position is changed, as I should. However, I am not getting any message when a joystick button is pressed.

If I use fChanged = false, the wParam of the periodic messages is updated correctly.

How can I get messages only when either position or button is changed, without using periodic messages?

+1  A: 

The documentation for joySetCapture says that if fChanged is true, then messages are only sent when the position changes by more than the threshold. Since it doesn't mention the buttons, I would assume that it doesn't send messages when buttons are pressed. This seems like poor design to me, but if that's how it is, then you have to deal with it.

Why don't you want to use periodic polling messages? As long as you set the polling interval to something reasonable (such as 16 ms for a 60 Hz refresh rate), I can assure you that polling the joystick is NOT going to be the bottleneck in your application, so it's not a question of performance. There's no reason to set the polling interval to something really small, because the hardware simply doesn't send out updates that fast, so you'd just be wasting cycles processing the same data.

Finally, the multimedia joystick API is somewhat dated and has been superseded by DirectX. You should use DirectInput instead so that you can handle joysticks with more than 4 buttons or more than 2 axes. Furthermore, if you're using Xbox 360 controllers, you should use the XInput library to process those.

Adam Rosenfield
A: 

Unless you need to be compatible with Windows before Win98, why not just use the DirectInput APIs? The joy* APIs are just a wrapper around the DirectInput APIs anyway.

Larry Osterman