Autohotkey automatic script triggering upon detection of Orbiter window

Ripley

Tutorial translator
Donator
Joined
Sep 12, 2010
Messages
3,133
Reaction score
407
Points
123
Location
Rome
Website
www.tuttovola.org
Hi, I'm new to Autohotkey.

I've read about it today in the Cougar MFD thread (and some time ago too), but I've never got into it.
Since I frequently use external MFDs, I'd like to understand how to make Orbiter window trigger a script automatically.

I've installed it, and copied the script found on orbiterwiki into a new ahk file...I've changed some MFD's sizes and they correctly show up at the pressure of some key combos.
Now I'm trying to make it "autostart" so, when an Orbiter window is detected, it automatically launches the script to open ExtMFDs.

I found this script which should do it, but I'm unable to edit it to my needs.

Any help?
 

yagni01

Addon Developer
Addon Developer
Donator
Joined
Feb 8, 2008
Messages
463
Reaction score
0
Points
16
Location
Atlanta, GA
What's the behavior?
Can you create a simple script to open Notepad when it detects Orbiter? Or get it to open the launchpad?
Maybe it's not waiting long enough. I seem to recall having trouble doing it on-the-fly, which is why the script uses a manual alt key when orbiter was already running. Don't have Orbiter at work, but you may have to have a scenario started for ExtMFD to come up.
 

Ripley

Tutorial translator
Donator
Joined
Sep 12, 2010
Messages
3,133
Reaction score
407
Points
123
Location
Rome
Website
www.tuttovola.org
I just started yesterday with Autohotkey, so, no, for the time being I can't "create a simple script to open Notepad when it detects Orbiter".

And I'm not that lazy...I can press a couple of keys to make the ExtMFDs pop-up.

It was just one of those semi-programmer wannabe things to achieve...

---------- Post added at 16:21 ---------- Previous post was at 11:54 ----------

Ok, I could now make the WinTrigger script execute Notepad on Orbiter launch.

Script just keeps on opening a new Notepad window each time Orbiter gains back focus after loosing it...anyway it works!

---------- Post added at 18:38 ---------- Previous post was at 16:21 ----------

Ok, fixed!
Now it automatically opens some MFDs whenever Orbiter is launched.

If interested, later I'll post the script, now I can't.
 
Last edited:

blixel

Donator
Donator
Joined
Jun 29, 2010
Messages
647
Reaction score
0
Points
16
I would be interested in comparing AutoHotKey scripts with you. I'm using a script to open either 2 or 4 external MFD's.

One problem I have with my external MFD script (and my Joystick script), is that they both seem to keep the CTRL key pressed after I open them. It's not that big of a deal. I'm in the habit of opening them and then tapping CTRL so my computer will release the CTRL key. But it's one of those things that I'd like to solve some day.

Here's my ExtMFD_2Displays.ahk file.

Code:
;
; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Win9x/NT
; Author:         A.N.Other <[email protected]>
;
; Script Function:
;	Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder)
;

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

SetKeyDelay,10,30

; Screen is 1280x1024

; For 4 MFD's, use size 569 width and 507 height
; Position 1 is x = 1600, y = 0
; Position 2 is x = 2311, y = 0
; Position 3 is x = 1600, y = 513
; Position 4 is x = 2311, y = 513

; For 2 MFD's, use size 634 width and 572 height.
; Position 1 is x = 1600, y = 0
; Position 2 is x = 2246, y = 0

pltMfd1PosX:=1600
pltMfd1PosY:=0
pltMfd1Width:=634
pltMfd1Height:=572

pltMfd2PosX:=2246
pltMfd2PosY:=0
pltMfd2Width:=634
pltMfd2Height:=572

WinActivate,Orbiter
Send {LCtrl down} ;
Send {F4} ;
Send {LCtrl up } ;
WinWait, Custom
Control, ChooseString, External Mfd, ListBox1, Custom
ControlClick, Button1, Custom
WinWait,MFD
WinSetTitle,pltMfd1
WinMove,pltMfd1,,%pltMfd1PosX%,%pltMfd1PosY%,%pltMfd1Width%,%pltMfd1Height%
WinGet,pltMfd1Handle,ID,pltMfd1
    
WinActivate,Orbiter
Send {LCtrl down} ;
Send {F4} ;
Send {LCtrl up } ;
WinWait, Custom
Control, ChooseString, External Mfd, ListBox1, Custom
ControlClick, Button1, Custom
WinWait,MFD
WinSetTitle,pltMfd2
WinMove,pltMfd2,,%pltMfd2PosX%,%pltMfd2PosY%,%pltMfd2Width%,%pltMfd2Height%
WinGet,pltMfd2Handle,ID,pltMfd2


; LET GO OF THE CONTROL KEY PLEASE!!!
Send {LCtrl up } ;
WinActivate,Orbiter
return
 

plainsight

New member
Joined
Jun 4, 2010
Messages
7
Reaction score
0
Points
0
^^Try to replace
Code:
Send {LCtrl down} ;
Send {F4} ;
Send {LCtrl up } ;

with "send ^{F4}"
 

Ripley

Tutorial translator
Donator
Joined
Sep 12, 2010
Messages
3,133
Reaction score
407
Points
123
Location
Rome
Website
www.tuttovola.org
I would be interested in comparing AutoHotKey scripts with you...
Here's "mine" (credit goes to whoever wrote the orbiterwiki script).
I didn't use the other "WinTrigger" script (which looks brilliant, btw).
I have removed all "keymappings" for MFD's buttons since I don't need them.

It opens 4 MFDs on the top row of main monitor (22" @ 1680x1050), and a 5th bigger one on a 8" @ 800x600 touchscreen I have on the left side. By simply editing those coordinates at the top of the script, you decide on which monitor the ExtMFDs will open.
Orbiter is set to run in a 1680x750 window.
Code:
#Persistent
WinWait,ahk_class Orbiter Render Window 
WinMinimize  ; Minimize the window found by WinWait.
	
SetKeyDelay,100,50

ExtMFD1PosX:=0
ExtMFD1PosY:=0
ExtMFD1Width:=350
ExtMFD1Height:=350

ExtMFD2PosX:=355
ExtMFD2PosY:=0
ExtMFD2Width:=350
ExtMFD2Height:=350

ExtMFD3PosX:=710
ExtMFD3PosY:=0
ExtMFD3Width:=350
ExtMFD3Height:=350

ExtMFD4PosX:=1065
ExtMFD4PosY:=0
ExtMFD4Width:=350
ExtMFD4Height:=350

ExtMFD5PosX:=-800
ExtMFD5PosY:=800
ExtMFD5Width:=658
ExtMFD5Height:=600

WinActivate,ahk_class Orbiter Render Window
Send ^{F4}
WinWait, Custom
Control, ChooseString, External Mfd, ListBox1, Custom
ControlClick, Button1, Custom
WinWait,MFD
WinSetTitle,ExtMFD1
WinMove,ExtMFD1,,%ExtMFD1PosX%,%ExtMFD1PosY%,%ExtMFD1Width%,%ExtMFD1Height%

WinActivate,ahk_class Orbiter Render Window
Send ^{F4}
WinWait, Custom
Control, ChooseString, External Mfd, ListBox1, Custom
ControlClick, Button1, Custom
WinWait,MFD
WinSetTitle,ExtMFD2
WinMove,ExtMFD2,,%ExtMFD2PosX%,%ExtMFD2PosY%,%ExtMFD2Width%,%ExtMFD2Height%

WinActivate,ahk_class Orbiter Render Window
Send ^{F4}
WinWait, Custom
Control, ChooseString, External Mfd, ListBox1, Custom
ControlClick, Button1, Custom
WinWait,MFD
WinSetTitle,ExtMFD3
WinMove,ExtMFD3,,%ExtMFD3PosX%,%ExtMFD3PosY%,%ExtMFD3Width%,%ExtMFD3Height%

WinActivate,ahk_class Orbiter Render Window
Send ^{F4}
WinWait, Custom
Control, ChooseString, External Mfd, ListBox1, Custom
ControlClick, Button1, Custom
WinWait,MFD
WinSetTitle,ExtMFD4
WinMove,ExtMFD4,,%ExtMFD4PosX%,%ExtMFD4PosY%,%ExtMFD4Width%,%ExtMFD4Height%

WinActivate,ahk_class Orbiter Render Window
Send ^{F4}
WinWait, Custom
Control, ChooseString, External Mfd, ListBox1, Custom
ControlClick, Button1, Custom
WinWait,MFD
WinSetTitle,ExtMFD5
WinMove,ExtMFD5,,%ExtMFD5PosX%,%ExtMFD5PosY%,%ExtMFD5Width%,%ExtMFD5Height%

WinActivate,ahk_class Orbiter Render Window
 
Last edited:

blixel

Donator
Donator
Joined
Jun 29, 2010
Messages
647
Reaction score
0
Points
16
Thanks for the reply. This is how the script was originally set up. But for some reason, when I just have it as

Code:
send ^{F4}

My system opens the Orbiter main menu (as if you just pressed F4 by itself), and then the script "hangs". For some reason, the ^ part of ^{F4} is ignored.

By changing it around to:

Code:
Send {LCtrl down} ;
Send {F4} ;
Send {LCtrl up } ;

It works on my system. I don't know why the other way doesn't work?


^^Try to replace
Code:
Send {LCtrl down} ;
Send {F4} ;
Send {LCtrl up } ;

with "send ^{F4}"
 

Ripley

Tutorial translator
Donator
Joined
Sep 12, 2010
Messages
3,133
Reaction score
407
Points
123
Location
Rome
Website
www.tuttovola.org
Following a PM I received from a forum member, here's a quick and dirty Orbiter2016 adaptation of my previous AHK script:

Code:
#Persistent
SetKeyDelay,50,40


ExtMFD1PosX:=0
ExtMFD1PosY:=0
ExtMFD1Width:=390
ExtMFD1Height:=390

ExtMFD2PosX:=0
ExtMFD2PosY:=360
ExtMFD2Width:=390
ExtMFD2Height:=390

ExtMFD3PosX:=0
ExtMFD3PosY:=720
ExtMFD3Width:=390
ExtMFD3Height:=390


if WinExist("Orbiter 2016 [D3D9Client]") {
    WinActivate
    Winmove, 424, 0

Send ^{F4}
Wingetpos, CustX, CustY, , , "Orbiter: Custom functions"
MouseMove, %CustX%+40, %CustY%+300
Mouseclick
WinWait, MFD
WinSetTitle, ExtMFD1
WinMove, ExtMFD1, , %ExtMFD1PosX%, %ExtMFD1PosY%, %ExtMFD1Width%, %ExtMFD1Height%


WinActivate, ahk_class "Orbiter Render Window"
Send ^{F4}
Wingetpos, CustX, CustY, , , "Orbiter: Custom functions"
MouseMove, %CustX%+40, %CustY%+300
Mouseclick
WinWait, MFD
WinSetTitle, ExtMFD2
WinMove, ExtMFD2, , %ExtMFD2PosX%, %ExtMFD2PosY%, %ExtMFD2Width%, %ExtMFD2Height%


WinActivate, ahk_class "Orbiter Render Window"
Send ^{F4}
Wingetpos, CustX, CustY, , , "Orbiter: Custom functions"
MouseMove, %CustX%+40, %CustY%+300
Mouseclick
WinWait, MFD
WinSetTitle, ExtMFD3
WinMove, ExtMFD3, , %ExtMFD3PosX%, %ExtMFD3PosY%, %ExtMFD3Width%, %ExtMFD3Height%

}

Script is optimized for this situation:

- I don't use a secondary touchscreen anymore
- my monitor is set @ 1920x1080
- Orbiter2016 runs in a 1500x1080 window
- I always use D3D9
- Windows app bar is set at "hide automatically"

The script opens three MFDs and puts them vertically at the left of Orbiter window.
 
Last edited:
Top