Author Topic: Autoit: Start program in background shift focus after x seconds  (Read 408 times)

rand0m

  • Full Member
  • ***
  • Posts: 76
    • View Profile
Autoit: Start program in background shift focus after x seconds
« on: September 18, 2018, 11:24:44 AM »
Demul is a special case in emulators where (afaik) pure command-line is not possible because Demul only accepts commands once its GUI is activated, bad for immersion because you don't go to game directly from AM and DEMUL GUI pops up. I'm using following for Gaelco via Demul:

#include <Misc.au3>
#include <_IsPressed360.au3>
$dll = DllOpen("xinput9_1_0.dll")
ShellExecute(@ScriptDir & "\demul.exe", ' -run=gaelco -rom="' & $CmdLine[1] & '"')
WinWaitActive("gpuDX11oldhw", "")
Send("!{ENTER}")
MouseMove(1920, 540, 0)
While 1
    If _IsPressed360("65536", $dll) And _IsPressed360("-32768", $dll) Then
      ProcessClose("demul.exe")
      ExitLoop
    EndIf
WEnd
DllClose($dll)


This script (made into an exe) works Ok. It opens demul, auto maximizes and hides the cursor but doesn't hide DEMUL GUI. Is it possible in this setup through additional commands that autoit opens demul in background and only shifts focus to Demul after 5 seconds when game starts so I don't see the Demul GUI?

hermine.potter

  • Sr. Member
  • ****
  • Posts: 404
    • View Profile
« Last Edit: September 20, 2018, 05:36:26 AM by hermine.potter »
AM Version : 2.4.0
Input : Mad Catz Brawlstick; Mouse; Keyboard; Xbox360 Wireless
Cabinet : Yes
OS : WindowsXP x86 SP3
System : Dell Precision T3500 ; Intel X5650 ; 4GB RAM
Emulators : zsnes; mame; dosbox; scummvm; bsnes; fusion; openbor; windows_games; winuae; video; flashgames; vice; visualboy

rand0m

  • Full Member
  • ***
  • Posts: 76
    • View Profile
Re: Autoit: Start program in background shift focus after x seconds
« Reply #2 on: October 16, 2018, 12:34:02 AM »
Thanks Hermine I actually used the linked setup as basic structure for my settings (just added up _IsPressed360.au3 from official autoit forums for xpad controls). The problem area is shifting of focus. I want the script to shift focus to demul after 3 seconds (so I don't see the demul GUI and shift focus only when game is loaded). Is there anyway to give a time variable within the script?

Something like:
1. Open Demul and load rom in background
2. Wait half a second
3. Send Alt+Enter in background
4. Wait 3 seconds
5. Shift Focus and bring demul to foreground


hermine.potter

  • Sr. Member
  • ****
  • Posts: 404
    • View Profile
Re: Autoit: Start program in background shift focus after x seconds
« Reply #3 on: October 16, 2018, 04:03:33 AM »
@ rand0m
Sure. There are three methods:

1) sleep timer
a simple sleep timer by command:
sleep(3000)
3000 means 3000 milliseconds (3 seconds);
half second (0,5 seconds) = sleep(500)

2) waiting for a certain dialog / dialouge / menu / window thats apperar to focus.
the script goes on, if a certain window gets focus.
commands:
winwait & winwaitactive
an example here

3) bring a active window to focus / foreground:
Opt("WinTitleMatchMode", 2)
WinActivate("Notepad")

the already started notepad editor gets to foreground / back to focus
AM Version : 2.4.0
Input : Mad Catz Brawlstick; Mouse; Keyboard; Xbox360 Wireless
Cabinet : Yes
OS : WindowsXP x86 SP3
System : Dell Precision T3500 ; Intel X5650 ; 4GB RAM
Emulators : zsnes; mame; dosbox; scummvm; bsnes; fusion; openbor; windows_games; winuae; video; flashgames; vice; visualboy

rand0m

  • Full Member
  • ***
  • Posts: 76
    • View Profile
Re: Autoit: Start program in background shift focus after x seconds
« Reply #4 on: October 18, 2018, 09:28:53 PM »
Thanks a lot for your help.