Jump to content
The simFlight Network Forums

HOW SEND A KEYBOARD KEY VIA SIMCONNECT VB.NET


Recommended Posts

I'm using this code for some KEY_EVENTS:

Class Form1

Dim fsx_simconnect As SimConnect

Const WM_USER_SIMCONNECT As Integer = &H402

....

Public Enum hSimconnect

group1

End Enum

Private Enum INPUT_ID 'should be used for sending Keyboard Input ?

INPUT0

End Enum

....

Private Enum EVENT_ID

EVENT_APon

EVENT_APoff

EVENT_FLAPSup

EVENT_FLAPSdn

EVENT_ALTOnOff

End Enum

....

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi, Pack:=1)> _

Structure Struct1

. '0

.

.

Public aponoffx As Single '7

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> Public Titlex As String

End Structure

....

Private Enum DEFINITIONS

Struct1

End Enum

Private Enum DATA_REQUESTS

REQUEST_1

End Enum

Enum UPEVENT 'should be used for sending Keyboard Input ?

WHATEVER

End Enum

Enum DOWNEVENT 'should be used for sending Keyboard Input ?

WHATEVER

End Enum

.....

Private Sub btnconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handle btnconnect.Click

'EXAMPLE

fsx_simconnect.MapClientEventToSimEvent(EVENT_ID.EVENT_APOnOff, "AP_MASTER")

fsx_simconnect.MapClientEventToSimEvent(EVENT_ID.EVENT_APon, "AUTOPILOT_ON")

fsx_simconnect.MapClientEventToSimEvent(EVENT_ID.EVENT_APoff, "AUTOPILOT_OFF")

.

.

fsx_simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "AUTOPILOT MASTER", "Bool", SIMCONNECT_DATATYPE.FLOAT32, 0, 7)

.

.

.

fsx_simconnect.RegisterDataDefineStruct(Of Struct1)(DEFINITIONS.Struct1)

AddHandler fsx_simconnect.OnRecvSimobjectData, New SimConnect.RecvSimobjectDataEventHandler(AddressOf simconnect_OnRecvSimobjectData)

fsx_simconnect.RequestDataOnSimObject(DATA_REQUESTS.REQUEST_1, DEFINITIONS.Struct1, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD.VISUAL_FRAME, 0, 0, 0, 0)

End Sub

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

If aponoff = 0 Then fsx_simconnect.TransmitClientEvent(DEFINITIONS.Struct1, EVENT_ID.EVENT_APon, 0, hSimconnect.group1, SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY)

If aponoff = 1 Then fsx_simconnect.TransmitClientEvent(DEFINITIONS.Struct1, EVENT_ID.EVENT_APoff, 0, hSimconnect.group1, SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY)

End Sub

Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

' Here should be the Transmit Key Event to the AUTOPILOT MASTER as a Example

End Sub

---------------------------------------

Everything is working OK.

Several trials with different Forums explanations for sending Keystrokes via Simconnect unfortunately without success.

I would need a precise Example how to implement the KEYSTROKE "Z" for the "AP MASTER" for example.

I think it is also possible to send a combination of Keystrokes like "shift+h".

Many thanks in advance.

regards,

Link to comment
Share on other sites

I would need a precise Example how to implement the KEYSTROKE "Z" for the "AP MASTER" for example.

I think it is also possible to send a combination of Keystrokes like "shift+h".

I'm afraid I don't know VB.NET, and this way of using SimConnect is not familiar to me. I think anyway you have posted to the wrong Forum -- this Forum is for FSUIPC and WideFS support, not SimConnect. There is a SimConnect forum over in AVSIM I beieve.

Regards

Pete

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.