Skino2412 Posted April 8 Report Share Posted April 8 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 Quote Link to comment Share on other sites More sharing options...
Paul Henty Posted April 8 Report Share Posted April 8 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 Quote Link to comment Share on other sites More sharing options...
Skino2412 Posted April 8 Author Report Share Posted April 8 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. Quote Link to comment Share on other sites More sharing options...
Paul Henty Posted April 8 Report Share Posted April 8 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 Quote Link to comment Share on other sites More sharing options...
Skino2412 Posted April 9 Author Report Share Posted April 9 Worked perfectly, as always. I have installed it in my programme and it works. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.