Skino2412 Posted April 8, 2022 Report Posted April 8, 2022 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
Paul Henty Posted April 8, 2022 Report Posted April 8, 2022 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 1
Skino2412 Posted April 8, 2022 Author Report Posted April 8, 2022 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.
Paul Henty Posted April 8, 2022 Report Posted April 8, 2022 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 1
Skino2412 Posted April 9, 2022 Author Report Posted April 9, 2022 Worked perfectly, as always. I have installed it in my programme and it works. 1
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