Is there a way to tell if a POV direction is held down?
Whenever I press down for example it immediately runs the onJoyMove callback twice for some reason.
So pressing down on the directional pad and holding it down traces this once
with the threshold at default and any other value:
releasing the down button traces this with threshold at default:
releaseing the down button traces nothing with threshold above a couple thousand.
(so basically no detecting a release event on the POV), which is bad because I want the threshold set to maybe 5000, since the analog sticks are real sensitive to movement.)
So I can never tell that the button is held down because it immediately thinks its released.
I tested this with 3 different controllers, and have tried to mess with the threshold value to see if it helps.
It doesnt seem to me that I can detect when a POV is held down and when a POV is released.
The POV values should only be in the range from 0 to 35,900. It's an angled expressed in degress (x 100). The threshold value only applies to X, Y, Z, R, U and V, not the the POV value. We only return the current POV value, if that hasn't changed then you get the same value back.
I don't think there's any good way to detect when YOUR control button is pressed and released. On MY (okay, Derek's) joystick it's a scroll wheel thngy so there is no press/release just a new value when you spin it.
A specific driver for your device may allow detection of the press and release of that button, but Windows makes all the joystick devices appear the same so you don't have to write code for them at the driver level.
The POV on my controlleris are the directional pad, up, down, left, right. Which yes I agree rangre from 0, 35,900. SwfStudio reports the default POV position as 65,535, when no button is pressed, which falls along the line as a couple other joy test programs I have that report -1 as the default position.
Ok with my other test program(not swfstudio) I can tell that when a button is released because it goes back to -1, so in swfstudio I should be able to tell that its not pressed when going back to 65,535, which it kind of does.
What the problem is that when pressing a POV direction the onJoyMove runs TWICE for some reason on each POV change which screws evertyhing up, this causes me not to be able to tell when it gets released because it keeps going back to 65535 on the second unexpected callback.
Basicically the onJoyMove gettings called two times real fast per button press messes up the POV detection. It shouldnt be getting called twice.
Running twice wouldnt be a big deal if the second time it ran it still reported the 18000 when Im holding down. But its resetting the position back to default.
What actually happens under the covers is the joystick info is queried at the interval specified by setPeriod. Each time we query the joystick we look for changes in any of the X,Y,Z,R,U,V and POV parameters. If any of the X,Y,Z,R,U,V parmeters have changed by a value >= the threshold since the last detected change then the new values are stored and returned. The POV data is saved when a change is detected, so even if the POV value hasn't changed, a change in X,Y,Z,R,U or V could cause the POV data to be returned.
The only solution I can see is to give the POV data its own notification where we can avoid sending data when there hasn't been a change.
You should also be able to do the same thing by ignoring back-to-back- duplicate values for the POV data in the onJoyMove handler.
I just ran a test with my Microsoft Sidewinder joystick and the values returned are as expected. I did see two calls when releasing the POV, but looking at all values returned (I'm dumping all values not just POV) I could see that the Y value changed, even though the joystick was sitting on my desk. The joystick has two modes: normal and motion-sense. When in motion-sense the D-pad is the POV. The problem, here, is that the motion-sense is sensitive and detects slight movements of the joystick. I was able to get it to not have any other values change by holding it down.
Check all values returned. If any of them are not what they were the previous time, that's why you're getting another event - a value has changed. As Tim mentioned, you'll just have to check that the previous data isn't what it was before.
Ok, there is something Im seeing here, my default values for x,y,z,r are
When I move a pov
I see tha z and r are chaging faithfully to 32255 and on release back to 32767, which is I guess why Im getting multiple callbacks.
Now how to ignore z and r, messing up pov numbers? Yes I can do a check I guess to see if z or r changed. Is that 32767 (default non pressed state) number the same for all joypads?
Not sure if that's the default for all, but I would assume so - middle position. Although I would assume it depends entirely on the joystick.
I think what you would want to do is check for the POV number. You probably don't care about z or r in your POV code. If the POV number hasn't changed since the last value, just ignore the call.
Tim mentioned potentially adding another event just for POV.
QUOTE: from mbd;45668
Yes this is possible but the issue Im running into with that is now I cant detect the release movement of the POV. I dont think I can simply ignore a change back to 65535, because I need to know when that occurs.The release state number and the 2nd callback number is the same exact number. And having users with different controllers , I taking a stab at whethere or not they have two events happen on their dpad or 1 event. On mine I can ignore the second event, but that second event on another users controller might actually be them releasing the button, where on my controller the second event is not.
I do think the best solution is to have a seperate POV event, because there might be different effects on different controllers.
Another example is that my controller is like yours, its very sensitive to even the slightest movement on the analog stick. This causes the onJoyMove to check my values again, and even with the dpad down at 18000, I can move the analog stick barely and the dpad will report 65535 even though I have the pov held down. So now that value has changed I cant listen anymore for a release event on the pov.
Ok I did some more testing and heres what I gathered up:
This isnt just a POV issue but with any item in onJoyMove:
If I get multiple callbacks due to multiple items being out of their default position then the second callback doesnt report the actually positions of any item in onJoyMove, it RESETS them.
I can move the analog stick down. Each movement of the analog will have 2 callbacks. The first reports where all items positions are like this.
The second callback(everything is reset)
So having a seperate POV event might not be the solution. It might be either to have serperate events for all items OR have a way to have the second callback report actual positions and not default values or not happen at all.
Can you post the example you are using? (FLA, SPF)
Did you have to install a driver, or have you updated the driver for that particular joystick?
Ok, I made a barebones swf,fla,spf and it still has this issue.
Also I took my logitech and unplugged it and am testing with a barebones controller now which doesnt have analog and just has 2 buttons.
Still the same issue when pressing the dpad. (2 callbacks);
Also when you first run the exe, onJoyMove is always called at least once on startup without ever even touching the joypad. Just have a joypad hooked up and watch the trace window run onJoyMove for no reason.
Also the second controller Im testing with is not one of those sensitive kinds of joypads either. Just a very basic controller, doesnt need drivers either.
We're polling the joystick position and comparing the last values against the current values. the first time the timer event fires there are no last values so you get the current values and then nothing until you actually move the joystick. So the initial event you see is generated right after you call start (before you touch the joystick). I can stop it from happening. I've added the onJoyPOV event so you can get POV data only when it really changes.