Author Topic: Focus problem using batch for pcsx2  (Read 190 times)

dukpoki

  • Full Member
  • ***
  • Posts: 89
    • View Profile
Focus problem using batch for pcsx2
« on: November 08, 2018, 12:33:58 AM »
So normally I've been running my pcsx2 games with the standard args in the cfg.  Like this for example:
Code: [Select]
executable           E:\pcsx2\pcsx2.exe
args                 "[romfilename]" --nogui --fullscreen --fullboot
rompath              E:\Sony Playstation 2\isos\Amplitude (USA)
ext                  .iso


Recently I decided to try batch files instead, so I switched over to this:
Code: [Select]
executable           cmd
args                 /c "[romfilename]"
rompath              E:\Sony Playstation 2\batchfiles
romext               .bat


The problem i'm having with the batch method, is every time I start a game in AM, it will boot but will be playing in the background with AM in focus instead.   I'm not sure what i'm doing wrong, or even how to fix this.  Here is a sample of a batch file for a game:
Code: [Select]
@echo off

d:
cd /D "E:\pcsx2\"
start pcsx2.exe "E:\Sony Playstation 2\isos\Amplitude (USA)\Amplitude (USA).iso" --nogui --fullscreen --fullboot

Anyone have a clue on how to fix this?
« Last Edit: November 08, 2018, 12:38:12 AM by dukpoki »

hermine.potter

  • Sr. Member
  • ****
  • Posts: 401
    • View Profile
Re: Focus problem using batch for pcsx2
« Reply #1 on: November 08, 2018, 01:15:08 AM »
What happens, if you set the resfix plugin to your emulator-display?
start AM > press TAB key > Plug-ins > ResFix > Enabled : Yes > Specific Emulators : name_of_your_emulator_display
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

dukpoki

  • Full Member
  • ***
  • Posts: 89
    • View Profile
Re: Focus problem using batch for pcsx2
« Reply #2 on: November 08, 2018, 09:22:37 AM »
What happens, if you set the resfix plugin to your emulator-display?
start AM > press TAB key > Plug-ins > ResFix > Enabled : Yes > Specific Emulators : name_of_your_emulator_display

Just tried it.  It didn't help.  PCSX2 is still running in the background.

dukpoki

  • Full Member
  • ***
  • Posts: 89
    • View Profile
Re: Focus problem using batch for pcsx2
« Reply #3 on: November 08, 2018, 12:18:41 PM »
I have another problem.  I tried creating batch files for Retroarch using a Sega CD game and tested it in AM to see if the same thing would happen (focus lost in the background) however, with the Retroarch batch, the game doesn't even boot at all.  Using Attract-console, I see that it launches the batch once selected but nothing ever transpires from it.  Note that the batch itself works perfectly fine when you double click it outside of AM.

Codes are as follow:

Code: [Select]
executable           cmd
args                 /c "[romfilename]"
rompath              E:\Emulation Data\Sega Genesis & CD\links
romext               .bat
system               Sega CD


Code: [Select]
@echo off

cd /D "E:\Running Emus\RetroArch\"
start retroarch.exe -L "E:\Running Emus\RetroArch\cores\genesis_plus_gx_libretro.dll" "E:\Emulation Data\Sega Genesis & CD\Sega CD isos\Snatcher (USA)\Snatcher (USA).cue"

I've also tried an alternative batch method which resulted in the same thing.

Code: [Select]
@echo off

start "" "E:\Running Emus\RetroArch\retroarch.exe" -L "E:\Running Emus\RetroArch\cores\genesis_plus_gx_libretro.dll" "E:\Emulation Data\Sega Genesis & CD\Sega CD isos\Snatcher (USA)\Snatcher (USA).cue"

xod

  • Full Member
  • ***
  • Posts: 25
    • View Profile
Re: Focus problem using batch for pcsx2
« Reply #4 on: November 08, 2018, 01:00:11 PM »
Note that the batch itself works perfectly fine when you double click it outside of AM.

Same thing is observed by me launching AM -> MAME 0.78, vs launching MAME 0.78 directly (without AM). Runs fine without AM, but with AM I have to either have any random application('s window) set to "always on top", or have terminated Explorer.exe (the shell), or run AM in windowed mode. Just for the purpose of gathering knowledge, have you tried having some application window "always on top" (while NOT minimizing that window) ? Try Task Manager and click menu item Options -> Always On Top. Then without minimizing that Task Manager window, launch AM and a game/bat, will it work then ? If yes, then we at least know that you are likely suffering the same probelm as me. To further verify, you should download Process Monitor. It's available for download at microsoft: https://docs.microsoft.com/en-us/sysinternals/downloads/procmon

If you download Process Monitor, I can help you to create a filter (not related to AM filters) for pcsx2.exe, and see how long/short that process runs. There is far more info provided by Process Monitor, but as I'm new and haven't learned much, I will go no further. And I write "help" because Process Monitor filters can be confusing for the beginner, but simple once you grasp them. If you're interested let me know.
« Last Edit: November 08, 2018, 01:53:07 PM by xod »

dukpoki

  • Full Member
  • ***
  • Posts: 89
    • View Profile
Re: Focus problem using batch for pcsx2
« Reply #5 on: November 09, 2018, 07:13:03 AM »
Note that the batch itself works perfectly fine when you double click it outside of AM.

Same thing is observed by me launching AM -> MAME 0.78, vs launching MAME 0.78 directly (without AM). Runs fine without AM, but with AM I have to either have any random application('s window) set to "always on top", or have terminated Explorer.exe (the shell), or run AM in windowed mode. Just for the purpose of gathering knowledge, have you tried having some application window "always on top" (while NOT minimizing that window) ? Try Task Manager and click menu item Options -> Always On Top. Then without minimizing that Task Manager window, launch AM and a game/bat, will it work then ? If yes, then we at least know that you are likely suffering the same probelm as me. To further verify, you should download Process Monitor. It's available for download at microsoft: https://docs.microsoft.com/en-us/sysinternals/downloads/procmon

If you download Process Monitor, I can help you to create a filter (not related to AM filters) for pcsx2.exe, and see how long/short that process runs. There is far more info provided by Process Monitor, but as I'm new and haven't learned much, I will go no further. And I write "help" because Process Monitor filters can be confusing for the beginner, but simple once you grasp them. If you're interested let me know.

FYI, I just tried the task manager with Always on Top enabled but it didn't work for me.  PCSX2 still runs in the background with AM in focus instead.

dukpoki

  • Full Member
  • ***
  • Posts: 89
    • View Profile
Re: Focus problem using batch for pcsx2
« Reply #6 on: November 09, 2018, 08:18:09 AM »
Update: I fixed the pcsx2 problem.  The issue was the "start" in the batch code.  Once I removed it, AM now properly gives focus to PCSX2.

So i went from this:

Code: [Select]
@echo off

cd /D "E:\pcsx2\"
start pcsx2.exe "E:\Sony Playstation 2\isos\Amplitude (USA)\Amplitude (USA).iso" --nogui --fullscreen --fullboot

to this:

Code: [Select]
@echo off

cd /D "E:\pcsx2\"
pcsx2.exe "E:\Sony Playstation 2\isos\Amplitude (USA)\Amplitude (USA).iso" --nogui --fullscreen --fullboot

And that magically did the trick!

Still can't figure out why RA is not working though.  Again, it doesn't even boot at all.

xod

  • Full Member
  • ***
  • Posts: 25
    • View Profile
Re: Focus problem using batch for pcsx2
« Reply #7 on: November 09, 2018, 01:47:24 PM »
When I first your first comment, and before reading the scipt you included, I was about to suggest "start /c ..." as well. But as it turned out for you, that was a/the problem.   Btw, there are plenty crazy things about cmd.exe, enough to make Bash to appear quite sane, hehehe. No command substitution being one, you instead have to use:

Code: [Select]
for /f ["<options>"] %<single-letter-variable> in ('<substituted command>') do <processing command goes here, it has access to %single-letter-variable, which is the output of 'substituted command'>
(the percent character/sign must be doubled (%%) in scripts of course, single ones are only for immediate commandline)

And there are limitations as well as dangers with that workaround.
Also, sometimes in cmd.exe you have to use "cmd /c <command>" rather than just "<command>", or things won't behave as expected and break. It's a mess, and more so to remember all these exception-al behaviors.

dukpoki

  • Full Member
  • ***
  • Posts: 89
    • View Profile
Re: Focus problem using batch for pcsx2
« Reply #8 on: November 10, 2018, 09:28:38 AM »
Another update:

I've done some N64 RetroArch batches and they work fine with AM.  It only seems to be my Sega CD batch that doesn't work.  Upon further testing I think the problem is the directory naming convention (look at the rompath in particular).

Currently my directory looks like this:

Code: [Select]
executable           cmd
args                 /c "[romfilename]"
rompath              E:\Emulation Data\Sega Genesis & CD\batch
romext               .bat
system               Sega CD

If I change it to this it works (I'm also moving the actual batch folder in explorer to match of course):

Code: [Select]
executable           cmd
args                 /c "[romfilename]"
rompath              E:\Emulation Data\Sega_CD\batch
romext               .bat
system               Sega CD

So in conclusion, the problem is either the "&", the "CD", or both, probably preceded by a space.  I've tried putting the whole path in quotation which didn't really do anything.  I am now completely stumped as to reasoning why this wouldn't work.  Also another odd thing about all this is that the original rompath with the spaces, "&", and "CD" was working just fine in the rompath field before I started switching over to batches.  Weird.  Of course, the easy solution is to just rename the folder to say "SegaCD" or "Sega_CD", which i'm totally doing.  But it would be nice to understand exactly where and why it's throwing off the code.

EDIT: The problem is the "&".  I've tried "SegaCD CD", "SegaCD &" , "Sega_&".   Anytime there's an "&" it seems to not work.  Still not sure why it doesn't work for batches while "&" is totally fine to use in the rompath any other time.
« Last Edit: November 10, 2018, 09:51:53 AM by dukpoki »