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

rand0m

  • Sr. Member
  • ****
  • Posts: 343
    • 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

  • Hero Member
  • *****
  • Posts: 767
    • View Profile
« Last Edit: September 20, 2018, 05:36:26 AM by hermine.potter »
AM Version : 2.6.1
Input : Mad Catz Brawlstick; Mouse; Keyboard; Xbox360 Wireless
Cabinet : Yes
OS : Windows10 Pro
System : Dell Precision T3500 ; Intel X5650 ; 12GB RAM

rand0m

  • Sr. Member
  • ****
  • Posts: 343
    • 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

  • Hero Member
  • *****
  • Posts: 767
    • 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.6.1
Input : Mad Catz Brawlstick; Mouse; Keyboard; Xbox360 Wireless
Cabinet : Yes
OS : Windows10 Pro
System : Dell Precision T3500 ; Intel X5650 ; 12GB RAM

rand0m

  • Sr. Member
  • ****
  • Posts: 343
    • 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.

Bgoulette

  • Sr. Member
  • ****
  • Posts: 116
  • I wrote a book.
    • View Profile
    • BlakeGoulette.com
Re: Autoit: Start program in background shift focus after x seconds
« Reply #5 on: December 26, 2018, 01:12:31 PM »
I don't know why this thread didn't get returned when I searched for this topic a day or two ago, but here's a simple series of files I've created for the same purpose:

http://forum.attractmode.org/index.php?topic=2669.0 (Sources in thread. Obviously, change paths to match your specific system!)

What I still can't figure out is how to throw up a blank screen to hide the initial demul window (and the rest of the desktop). I suppose there must be some way to write a simple program that slaps a solid black background on top of everything first, then load demul and wait for its window to "change" (rom to load), then kill the "black" process? I don't know enough about windows to know how to create such a program, though. But now I'm even more curious than I was, so it seems like I'll be looking in to it... :)

Edit: I modified the script in the above post a little (and added attachments): now, it draws a 1x1 black pixel across the whole screen before demul loads a rom. There's still a brief flash, but it's a little better!
« Last Edit: December 26, 2018, 02:03:34 PM by Bgoulette »

rand0m

  • Sr. Member
  • ****
  • Posts: 343
    • View Profile
Re: Autoit: Start program in background shift focus after x seconds
« Reply #6 on: December 27, 2018, 04:33:54 AM »
What I still can't figure out is how to throw up a blank screen to hide the initial demul window (and the rest of the desktop). I suppose there must be some way to write a simple program that slaps a solid black background on top of everything first, then load demul and wait for its window to "change" (rom to load), then kill the "black" process? I don't know enough about windows to know how to create such a program, though. But now I'm even more curious than I was, so it seems like I'll be looking in to it... :)

Great work on that .ahk script, I'll make sure to try it soon. For a big black screen you can use "Attrcat True Balck" app by forum member Oomek from here > http://forum.attractmode.org/index.php?topic=1569.0.

As for general Demul emulation :

1- One way is to configure it so focus only shifts when the rom is loaded. Here the primary issue is of shifting focus from AM to Demul and all the loading takes place into the background. Not a good solution overall because loading can take >4 secs and in default state there is nothing to indicate to the user that file is being loaded in the background. Shifting of focus from AM to Demul and back can also be tricky, it was not uniform my case. 

2- Keilmillerjr's Fade plugin can be of assistance, it supports picture (loading screen) and can be timed. So from the moment you press select till Demul loads and runs the rom a simple fade screen with some text (e.g. loading) can be used. Plugin is available here> https://github.com/keilmillerjr/fadetogame-plugin. Infact I think it can support artworks so e.g. wheels can be used as a loading screen making it look more polished. 

IMHO script loading in background with fade screen in-front would make for a more immersive experience and thats exactly what I was working on before I retried reicast and decided to stick with it.

Bgoulette

  • Sr. Member
  • ****
  • Posts: 116
  • I wrote a book.
    • View Profile
    • BlakeGoulette.com
Re: Autoit: Start program in background shift focus after x seconds
« Reply #7 on: December 27, 2018, 08:19:53 PM »
Made a couple more tweaks:

Code: [Select]
#SingleInstance, force
SetTitleMatchMode, 1

ScreenW := A_ScreenWidth
ScreenH := A_ScreenHeight
FontSize := 64

SubTextY := (ScreenH - FontSize) / 2

; Move the mouse to the bottom right:
MouseMove % ScreenW, ScreenH, 0

; Display a single image as a SplashImage:
SplashImage, , b w%ScreenW% h%ScreenH% x0 y0 zw%ScreenW% zh%SubTextY% fs%FontSize% ctWhite cwBlack, Loading..., , demulSplashWindow, OneTwoPunchBB-Italic

RomName := A_Args[1]
Run %ComSpec% /c "demul.exe -run=naomi -rom=%RomName%", , Hide
; Run %ComSpec% /c "demul.exe -run=naomi -rom=mvsc2", , Hide

; When demul.exe loads a rom, its title changes to a string beginning with gpuDX11hw:
; (Could change dep. on DirectX ver., but just checking the process jumps the gun)
WinWaitActive, gpuDX11hw, , 10
SplashImage, Off
Send !{Enter}
return

#IfWinActive, ahk_exe demul.exe
    Esc::
    WinClose, A
    ExitApp

#IfWinActive

No external image file needed: I didn't realize ahk's SplashImage can be left blank and a background color provided as an option. This works for me! (in conjunction with the following batch file):

Code: [Select]
@echo off
dfs.exe %1

Unrelated (well, partially), but Reicast: is it possible to use without retroarch? I'm really an emulation noob, so I apologize if that's a stupid question!

rand0m

  • Sr. Member
  • ****
  • Posts: 343
    • View Profile
Re: Autoit: Start program in background shift focus after x seconds
« Reply #8 on: December 29, 2018, 06:43:16 PM »
Unrelated (well, partially), but Reicast: is it possible to use without retroarch? I'm really an emulation noob, so I apologize if that's a stupid question!

Worry not, emulation can be tricky business. You can find windows version of reicast here> http://builds.reicast.com/ (scroll downwards). If that doesn't work try the version available here > http://www.emu-france.com/emulateurs/5-consoles-de-salon/30-sega-dreamcast/7063-reicast-x64/

You will need to create /data in reicast folder and place BIOS files there (dc_bios.bin & dc_flash.bin).

Is there any reason you are not opting for Retroarch? It offers a lot of good things.


Bgoulette

  • Sr. Member
  • ****
  • Posts: 116
  • I wrote a book.
    • View Profile
    • BlakeGoulette.com
Re: Autoit: Start program in background shift focus after x seconds
« Reply #9 on: January 04, 2019, 06:39:35 AM »
Quote from: rand0m
Is there any reason you are not opting for Retroarch? It offers a lot of good things.

It's probably a lack of knowledge on my end. I'm mostly interested in arcade (vs. console) games, so I compiled MAME and goofed around with demul, and that handles most of my interests. RetroArch just seemed like immense overkill for my interests. That said, I just downloaded it. :)