Quick issue about HIDConfigureAction

There are not exactly few, but neither really lots of people who know what HIDConfigureAction is. I’m quite certain that nobody who visits my site and tells me about it is among them. There is one exception, but as far as I know he only visited my site once and anyway, that’s not the point. In short: HIDConfigureAction is a function of Apple’s HID Utilities. You call it with a time and get, if something made a significant movement, the device and part of the device that caused this movement. This is useful and probably meant for games, where you click on the function you want to have assigned to a different key and then press that very key. Works like a charm, except for one big problem I just had:

How can one use it to detect movement on a mouse axis?

Problem is that there is a percentage you have to be above to get your movement noticed. This is, as percentages are, based on the max and min values the particular thing can have. What is the minimum or maximum for mouse movement within a very short time?

Apple assumes ±32767, which would happen to be minimum and maximum of a 32 bit number for the clueless among us. However, as other Apple sample code shows, the actual value hardly passes ±60. Obviously, you have to change the calculation of the percentage.

The solution

It’s easy as Apple includes the source code for you to tinker with. To fix the behaviour, first you have to identify whether you are dealing with a mouse axis. Then you have to create a new percentage that makes sense. There are two approaches to doing this: The technically correct one and the lazy one. I’m doing the latter.

You’ll need to open HID_Config_Utilities.c and change line 127 from

delta = (float)(pElement->max - pElement->min) * kPercentMove * 0.01;


if (pElement->max > 10000)
    delta = 10;
    delta = (float)(pElement->max - pElement->min) * kPercentMove * 0.01;

Recompile, works. Obviously, this ain’t real good style and the fact that I only tested it right now on only one computer with only one mouse is reason for panic. It is even more reason for panic when you see how different and illogical input device values can be. But I hope that I helped one or two guys who come here, googling for Joystick and Cocoa or whatever, and even if I didn’t, maybe I gave someone a good starting point. Tell me whether it works for you.

Written on February 13th, 2006 at 09:37 pm


    New comments can no longer be posted because it got to annoying to fight all the spam.