Jump to content
The simFlight Network Forums

FSUIPCConnection.SendKeyToFS - Question


Recommended Posts

I want to use the function to send keystrokes to the Sim. The aircraft I am controlling has no offsets but is controlled by selectable key combinations.

With

FSUIPCConnection.SendKeyToFS(Keys.1, SendModifierKeys.Alt, Me.ParentForm)

I send Alt 1 to the simulator. This works perfectly, of course.
Can I replace the 1 with a string/variable? My programme writes the key command given by the user into a string Taste1, so I cannot specify the key directly.

FSUIPCConnection.SendKeyToFS(Keys.Taste1, SendModifierKeys.Alt, Me.ParentForm) 

Peter

Link to comment
Share on other sites

Hi Peter,

You can do this by converting the string into the 'Keys' enum using Enum.Parse().

(I think when you wrote Keys.1 you mean Keys.D1).

        Dim Taste1 As String = "D1"
        Dim Taste1Enum As Keys = Keys.None
        If [Enum].TryParse(Of Keys)(Taste1, Taste1Enum) Then
            ' Parse OK. Taste1Enum now has correct value
            FSUIPCConnection.SendKeyToFS(Taste1Enum, SendModifierKeys.Alt, Me.ParentForm)
        Else
            ' Text in Taste1 is not a valid Keys enum value
        End If

For this to work, the string will need to be exactly the same as the Enum value text. 

Paul

  • Thanks 1
Link to comment
Share on other sites

 

Thank you again for your valuable help.


The variable ENGINE has the letter A stored.
With this code I send A to the simulator? And any other single character that the user stores in My.Sttings.Engine?

 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim Taste1 As String = My.Settings.Engine
        Dim Taste1Enum As Keys = Keys.None
        If [Enum].TryParse(Of Keys)(Taste1, Taste1Enum) Then
            FSUIPCConnection.SendKeyToFS(Taste1Enum, SendModifierKeys.Alt, Me.ParentForm)
 Else
            MsgBox(My.Settings.Engine & " could not be sent!",, AppTitle)
        End If
    End Sub

The whole point is that the user determines which character is to be assigned to the function. And I store this character in My.Settings.Engine. In this case for the display of the engine page of an Airbus ECAM.

 

Screenshot 2022-04-08 19.32.41.png

Link to comment
Share on other sites

Yes that looks like it would work.

You will need to adjust the Enum.Parse call to make it case-insensitive since you are using lower-case letters: Pass 'True' as the second parameter.

Quote
If [Enum].TryParse(Of Keys)(Taste1, True, Taste1Enum) Then

Paul

  • Thanks 1
Link to comment
Share on other sites

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.