I am using joySetCapture with fChanged (4'th parameter) = true.
我正在使用joySetCapture和fChanged(第4个参数)= 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.
如果我使用fChanged = false,则周期性消息的wParam会正确更新。
How can I get messages only when either position or button is changed, without using periodic messages?
只有在更改位置或按钮时才能获取消息,而不使用定期消息?
2 个解决方案
#1
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.
joySetCapture的文档说如果fChanged为true,则只有当位置变化超过阈值时才会发送消息。由于它没有提到按钮,我认为按下按钮时它不会发送消息。对我来说,这似乎是糟糕的设计,但如果是这样,那么你必须处理它。
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.
为什么不想使用定期轮询消息?只要将轮询间隔设置为合理的值(例如60 Hz刷新率为16 ms),我可以向您保证轮询操纵杆不会成为应用程序的瓶颈,因此这不是性能问题。没有理由将轮询间隔设置为非常小的,因为硬件不会快速发送更新,因此您只是浪费处理相同数据的周期。
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.
最后,多媒体操纵杆API有点过时,并已被DirectX取代。您应该使用DirectInput,以便您可以处理具有4个以上按钮或2个以上轴的操纵杆。此外,如果您使用的是Xbox 360控制器,则应使用XInput库来处理这些控制器。
#2
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.
除非您需要在Win98之前与Windows兼容,为什么不直接使用DirectInput API?无论如何,joy * API只是DirectInput API的包装器。
#1
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.
joySetCapture的文档说如果fChanged为true,则只有当位置变化超过阈值时才会发送消息。由于它没有提到按钮,我认为按下按钮时它不会发送消息。对我来说,这似乎是糟糕的设计,但如果是这样,那么你必须处理它。
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.
为什么不想使用定期轮询消息?只要将轮询间隔设置为合理的值(例如60 Hz刷新率为16 ms),我可以向您保证轮询操纵杆不会成为应用程序的瓶颈,因此这不是性能问题。没有理由将轮询间隔设置为非常小的,因为硬件不会快速发送更新,因此您只是浪费处理相同数据的周期。
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.
最后,多媒体操纵杆API有点过时,并已被DirectX取代。您应该使用DirectInput,以便您可以处理具有4个以上按钮或2个以上轴的操纵杆。此外,如果您使用的是Xbox 360控制器,则应使用XInput库来处理这些控制器。
#2
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.
除非您需要在Win98之前与Windows兼容,为什么不直接使用DirectInput API?无论如何,joy * API只是DirectInput API的包装器。