Jump to content
Sign in to follow this  
friedrich

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) Handles 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,

Share this post


Link to post
Share on other sites

Friedrich,

 

As that as I know, there is no API in SimConnect that you can use to send a key stroke.

 

What is possible is to detect (in your program) that a key was activated in FSX and to send back an event to fSX in order to trigger some process. You can find an example (C++) here :

http://msdn.microsoft.com/en-us/library/cc730335.aspx

 

Patrick.

Share this post


Link to post
Share on other sites

Friedrich,

 

As that as I know, there is no API in SimConnect that you can use to send a key stroke.

 

What is possible is to detect (in your program) that a key was activated in FSX and to send back an event to fSX in order to trigger some process. You can find an example (C++) here :

http://msdn.microsof...y/cc730335.aspx

 

Patrick.

 

Hi,

thanks for your comment. In fact it seems not possibile. Maybe the only way around is to send a Keystroke via the programmer software to the Window/Program that has the focus. This is possible but i believe not very save with FSX.

 

regards

Share this post


Link to post
Share on other sites

The usual logic with simConnect is generally not to send a key but an event.

For instance, if you want to turn on / off the AP Master, send an event AP_MASTER using the API SimConnect_TransmitClientEvent.

You will find the list of events in the SDK documentation also samples.

 

Patrick.

Share this post


Link to post
Share on other sites

The usual logic with simConnect is generally not to send a key but an event.

For instance, if you want to turn on / off the AP Master, send an event AP_MASTER using the API SimConnect_TransmitClientEvent.

You will find the list of events in the SDK documentation also samples.

 

Patrick.

 

Hi,

in fact that is what i'm doeing as explained above with my first Post.

 

Anyway i will check some different possibility and revert if successfull.

 

regards,

Share this post


Link to post
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
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...