Jump to content
Sign in to follow this  
huha001

HowTo: Combining AAO with VB Scripts to send virtual keys

Recommended Posts

I want to share a solution how to send virtual keys to another computer if you are running AAO and FS2020 on different computers:

This can be used to send all the "nonworking" Simevents of the Asobo SDK like Toggle Pause , Toggle ATC window, or VIEW and CAMERA events via key strokes to another computer

 
You need to attach with ONCE this initialization script to aircraft automated scripts, where you can direct the virtual keys either to the same computer or to a networked computer by macros:
 

//·Use·0·if·FS2020·runs·on·the·same·computer·like·AAO
//0·(>L:AAO_ON_OTHER_COMPUTER)·

//·Use·1·if·FS2020·runs·on·a·different·computer·like·AAO
1·(>L:AAO_ON_OTHER_COMPUTER)·

//In·that·case·the·IP·address·and·the·AAO·WebAPI·port·must·be·specified·for·the·FS2020·computer:
'192.168.178.29:9080'·(>L:FS2020_IP_ADDRESS_PORT,·String)·

//Location·of·the·.vbs·script·to·send·commands·to·the·FS2002·computer
'C:\Users\<username>\Documents\LorbyAxisAndOhs·Files\Scripts\huha001-Cessna152\VB_Scripts\SendAAOScript.vbs'·(>L:VB_SCRIPT_FILE,·String)

(SPLIT:100)

//Define·the·generic·(SPLIT:100)
'(SPLIT·:·100)·'··(>L:SPLIT,·String)

//Define·the·generic·command·string·variable·part1:·and·store·in·(L:VBS_SEND_MACRO,·String)
'·'·(>L:VBS_SEND_MACRO1,·String)·
'(EXEC:wscript.exe,·"'·(L:VB_SCRIPT_FILE,·String)·scat·
'"·"'·scat·
(L:FS2020_IP_ADDRESS_PORT,·String)·scat·
'"·"'·scat·(>L:VBS_SEND_MACRO1,·String)

//Define·the·generic·command·string·variable·part2
'")'·(>L:VBS_SEND_MACRO2,·String)

//switch now depending on L:AAO_ON_OTHER_COMPUTER the configuration of the macro with local variables
(L:AAO_ON_OTHER_COMPUTER)·0·==·if{
'·'·(>L:VBS_SEND_MACRO1,·String)
'·'·(>L:VBS_SEND_MACRO2,·String)
//Define·the·real·(SPLIT:100)
'(SPLIT'·':100)·'·scat·(>L:SPLIT,·String)
}

 
You have to replace your user account name <username> and ip address of the FS2020 computer and to check all your paths.
 
Then you can use the following VB script which must be in C:\Users\<username>\Documents\LorbyAxisAndOhs·Files\Scripts\huha001-Cessna152\VB_Scripts\SendAAOScript.vbs :

'***********************************************************************************************
' .vbs script to send an AAO script sequence to the Fs2020 computer via the AAO webinterface
'***********************************************************************************************
' Version 1.0
' AAO must be run offline in admin mode on the FS2020 computer with the WEB API enabled
' The windows firewall must have a rule defined for both the FS2020 and the AAO computer
' Call: wscript.exe SendAAOScript.vbs
' Store the arguments in a variable:

' ipaddress: ipaddress of the FS2020 computer with the AAO port number (example: localhost:9080 or 192.168.178.27:9080)
' scriptvar: string with AAO script sequence being executed on the FS2020 computer (example: "99 (>L:MYDEBUGVAR)"

Dim o, scriptVar,ipaddress, debug
On Error Resume Next
debug = True

ipaddress = ""
scriptVar = ""

'DEBUG:
If debug Then
  Set objFSO=CreateObject("Scripting.FileSystemObject")
'INSTALLER_CHANGE_BEGIN
  outFile="C:\Users\<username>\Documents\LorbyAxisAndOhs Files\Scripts\huha001-Cessna152\VB_Scripts\logfile.txt"
'INSTALL_CHANGE_END
  Set objFile = objFSO.CreateTextFile(outFile,True)
  objFile.Write "count=" & Wscript.Arguments.Count & vbCrLf
End If

If Wscript.Arguments.Count > 0 then
    ipaddress = Replace(Wscript.Arguments(0),"&gt;",">")
end if

' you must replace > and < and : and probably  a few more for all script commands
if Wscript.Arguments.Count > 1 then
    scriptVar = Replace(Wscript.Arguments(1),"&gt;",">")
    scriptVar = Replace(scriptVar,"&lt;",">")
    scriptVar = Replace(scriptVar,"&colon;",":")
    scriptVar = Replace(scriptVar," : ",":")
end if

'send the script now to the Fs2020 computer
Set o = CreateObject("MSXML2.XMLHTTP")
o.open "POST", "http://" & ipaddress & "/webapi?json={""scripts"": [ { ""code"":"" " & scriptVar & " "" }]}", False
o.send
If Err.Number <> 0 Then
   If debug Then
     objFile.Write "ipaddress=" & ipaddress & vbCrLf
     objFile.Write "scriptVar=" & scriptVar & vbCrLf
     objFile.Write "There's been an error sending the http request to the AAO webserver" & vbCrLf
     objFile.Write "Is the AAO WEBAPI enabled and is AAO running in Admin mode?" & vbCrLf
     objFile.Close
     WScript.Quit 1    
   End If
End IF
' o.responseText now holds the response as a string.

'you could access with a running .vbs script to AAO via the WEB interface for simvars or also send via .vbs scripts events to AAO

'DEBUG:
if debug Then
  objFile.Write "ipaddress=" & ipaddress & vbCrLf
  objFile.Write "scriptVar=" & scriptVar & vbCrLf
  objFile.Write "responseText=" & o.responseText & vbCrLf
  objFile.Close
End If

 
Last, the virtual key is then sent by a RPN script just with a single line depending on your configuration in the initialization script either directly on the same computer or via vb script to another computer:
//**************************************************************************
//·Script·for·Virtual·Keys·for·PAUSE
//**************************************************************************
//·Virtual·Key:·Pause
@VBS_SEND_MACRO1·(FOCUS:flightsimulator)·@SPLIT·(VKD:69-197-19)·@SPLIT·(VKU:69-197-19)·@VBS_SEND_MACRO2
 
 
Explanations:
The main idea is that you are sending by macro definitions the virtual key(s) either directly to the same computer or via a VB script to another computer using the AAO webinterface. For that AAO must run on the Fs2020 computer in admin mode without being connected to the Fs2020 computer in the offline modus. This instance of AAO just receives via the webinterface virtual key commands from the AAO computer.
 
Please note that you must define separate @SPLIT macros, because AAO does not allow within a String the SPLIT command (or any other simulation variable!!!).
AAO would execute it as a command or replace the simvariable by its value.
 
Then the macro definitions start in an EXEC command the VB script with the virtual key commands as an argument.
 
The VB script removes the spaces before and after the colon (which prevents AAO to execute the Split command from the string) and sends via http request the virtual script command to the other computer via the AAO webinterface
Most of the script is just for debugging and could be removed.
 
Needless to say that this concept of starting VB scripts via AAO with arguments, VB script processing and transferring back the results to AAO via the Web interface enables a lot more complex procesing opportunities.
 
I know this is complicated but you can watch the execution depending on the configuration in the 'Watch AAO Script processing' window step by step.

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...