VFRJON Posted November 13, 2007 Report Posted November 13, 2007 Hi, At present Using a program I have written in c# , I am able to read the data from my joystick button presses (all 112 of them!!!!) using directinput and directX and then send data back to FSUIPC. Its working great, and now I have no limitation of the windows 32 button API and I can throw away the joy to key software I have. Couldnt believe how easy it was!! The problem I am having, is trying to work out an algorithm so that when I hold the button down the value for the offset doesn't keep toggling. What I am looking for is something like the tickbox in the FSUIPC module that controls whether the button is to be repeated while held, except I want it in reverse. I'm programming in C# using Phentys dotnet.dll Can anyone help me with this, doesn't matter what language its done in, as long as I get an idea of where to start, hopefully I can nut it out. Jon
Pete Dowson Posted November 14, 2007 Report Posted November 14, 2007 The problem I am having, is trying to work out an algorithm so that when I hold the button down the value for the offset doesn't keep toggling. What I am looking for is something like the tickbox in the FSUIPC module that controls whether the button is to be repeated while held, except I want it in reverse. To have a joystick button repeating surely necessitates EXTRA code? You notice the change from "not pressed" to "pressed", which happens only once -- then, later you get the "pressed" to "unpressed" change. To get repeats in-between would mean extra code with a timer, to see if it is still pressed. Merely by-pass that to avoid repeats! If your hardware is sending repeats and mis-representing the "press" and "released" states of the buttons, you have a hardware problem. If you can't make it work correctly I am not sure what you can do, other than ignore presses which occur too close to previous ones. But that can be quite limiting in the button usefulness. Regards Pete
VFRJON Posted November 14, 2007 Author Report Posted November 14, 2007 Thanks for the answer Pete, I think you may have got me thinking about something....... "not pressed" to "pressed", which happens only once -- then, later you get the "pressed" to "unpressed" change. I have seen this in the windows API, so I guess I have to see if it is available in directinput / directx. I'm sure it would be there somewhere! Its definitely not hardware related, have had this working for years with various software, I'm 100% confident its something I have missed in the new code I have written. The button, while being held down causes each cylce of the code to see that the button is pressed, and therefore toggle the value I am writing to a particular offset. For example if (pressed_button == "37" & (audio_status_lights.Value[3])) { audio_status_lights.Value[3] = false; } else if (pressed_button == "37" & (!audio_status_lights.Value[3])) { audio_status_lights.Value[3] = true; } So if button "37" is held down, cycle 1 sets audio_status_lights.Value[3] false cycle 2 sets audio_status_lights.Value[3] true cycle 3 sets audio_status_lights.Value[3] false cycle 4 sets audio_status_lights.Value[3] true cycle 5 sets audio_status_lights.Value[3] false cycle 6 sets audio_status_lights.Value[3] true cycle 7 sets audio_status_lights.Value[3] false cycle 8 sets audio_status_lights.Value[3] true ..................... and its a lucky dip as to what the status is, when you take your finger off the button!
Pete Dowson Posted November 14, 2007 Report Posted November 14, 2007 Thanks for the answer Pete, I think you may have got me thinking about something......."not pressed" to "pressed", which happens only once -- then, later you get the "pressed" to "unpressed" change. I have seen this in the windows API, so I guess I have to see if it is available in directinput / directx. I'm sure it would be there somewhere! What are you expecting to see in these interfaces? They simply tell you if the button is PRESSED or NOT PRESSED. Surely your program reads the fact that they are pressed or not, so you know when the button changes from one state to the other!? I'm 100% confident its something I have missed in the new code I have written. The button, while being held down causes each cylce of the code to see that the button is pressed, and therefore toggle the value I am writing to a particular offset. So you have deliberately programmed it to only act on button state, and not to only act when the state changes! No wonder it repeats! Just store the complete button state (all zero initially), then Exclusive Or that previous state with the new state on each cycle, and act on the changes. 0 -> 1 = press, 1 -> 0 is release. It isn't complicated, but any processing of buttons surely needs to detect user action, not static state! Buttons are for user actions, after all! Pete
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now