Jump to content
The simFlight Network Forums

Recommended Posts

Posted

I am trying to see when a user pressed the Shift Z Key. Below is my function. Please advise.

Public Function ShiftZ() As Boolean

FSUIPC_Write(&H3210, 90, Token, result) 'Z

FSUIPC_Process(result)

FSUIPC_Write(&H3211, 1, Token, result) ' SHIFT

FSUIPC_Process(result)

FSUIPC_Read(&H3213, 1, Token, result)

If FSUIPC_Process(result) Then

FSUIPC_Get(Token, result)

Debug.WriteLine(Token.ToString + " " + result.ToString)

End If

Return result <> 0

End Function

Posted
I am trying to see when a user pressed the Shift Z Key. Below is my function. Please advise.

First NEVER split off every single FSUIPC Write into a separate Process. Each time you call FSUIPC_Process you are causing a switch to FS. It is grossly inefficient. The whole point of separating the Read and Write operations from the Process is for efficiency. You build up a list of all the reads and writes you want to do in each of your program's cycles, then send them all to FS in one FSUIPC_Process call!

Second, you cannot and must not write to 3210 unless you know that slot is free -- otherwise you could be destroying some other program's ability to capture keys it wants. Please read the documentation. You need to search FROM 3210 to find an empty slot. Best to read the array of 32-bit integers at 3210, then find one which is all zero. That will be free to use. Write a 32-bit integer to it, not a series of single bytes. In your case, for Shift+Z the 32-bit value is hexadecimal &H0000015A, or in decimal (1 x 256) + 90 = 346.

That's the initialisation.

In your code you seem to think you can write the request then immediately read it back to detect the key press, but how is that going to work? There's zero possibility of the user being able to press Shift Z in zero time and at the precise instant between you writing the request and immediately reading it back.

Later, somewhere else in your program, and once each cycle (say every second or half-second or whatever) you read back the value to see if the key has been pressed yet. Not the "byte at 3213" but the one at 3 + the offset you found and wrote to.

Once you've detected the keypress you need to write 0 back to that byte to detect the keypress again.

Really, from the code snippet you have posted, it looks as if you aren't a programmer (yet). Is this right? If so I really would suggest getting some practice first doing a different project, as what you want to do here is not something for complete beginners, even using VB.

I am not familiar with VB so I cannot even do it for you, but possibly some other VB programmers visiting will be able to help you further.

Regards

Pete

Posted

Hi Pete,

Thanks for clearing that up - I have very little experience in programming the FSUIPC – I just browsed thought some code snippets I got all over. I should have studied the manual better before asking the question, but time is tight and I am trying to help out at the club.

As for the comment:

Really, from the code snippet you have posted, it looks as if you aren't a programmer (yet). Is this right? If so I really would suggest getting some practice first doing a different project, as what you want to do here is not something for complete beginners, even using VB.

Place a person in a bad light and was not appreciated, I did not under stand the model I was working with and responded with that knowledge not my capabilities as a programmer . But thanks for the help.

Thunis

Posted

Place a person in a bad light and was not appreciated

Well, I apologise. It was not intended as any sort of insult. But the problem I have is that there have been many complete beginners trying to tackle programming to interface to FS over the years, and it really is not a good place to start, at all.

Regards

Pete

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.