Jump to content
LaunchBox Community Forums

Exiting Yuzu Emulator using a hotkey (ESC)


Wolf3434
 Share

Recommended Posts

Hi All. I read up on this but I still can't get it

Tried adding this to the Exit autohotkey script.

Also added ESC as the hotkey under exiting yuzu when playing. Tried both but the only way I can exit is ALT-F4.

 

 

; This section closes Yuzu when pressing Escape
$Esc::
{
    Process, Close, {{{StartupEXE}}}
}

 

Anybody get yuzu to exit on a hotkey to work?

Edited by Wolf3434
Link to comment
Share on other sites

  • 1 month later...
On 6/14/2021 at 5:57 AM, Koroth said:

Use this:


$Esc::
{
WinClose, ahk_exe {{{StartupEXE}}}
}

Add it to LaunchBox > Tools > Manage Emulators > Yuzu > Running AutoHotKey Script tab. Also make sure you do not run yuzu.exe with admin privileges.

From my understanding, if you use an Nvidea card, you need to run Yuzu as Admin so it can utilize the threaded optimization features via the Nvidea Control Panel??? Has it changed?

Link to comment
Share on other sites

On 8/6/2021 at 11:45 PM, Wanderer189 said:

From my understanding, if you use an Nvidea card, you need to run Yuzu as Admin so it can utilize the threaded optimization features via the Nvidea Control Panel??? Has it changed?

No, I don't think that it has changed. But of course you don't NEED Yuzu to run as admin for it being able to run. But I have found a way to run Yuzu as admin, without UAC prompt and with an exit script. First I added an "Yuzu Admin" emulator to LaunchBox. This is just an AutoHotKey script. When I start a Switch game in LaunchBox, LaunchBox passes the rom name to this "Yuzu Admin" script. This "Yuzu Admin" script then copies the rom name to a second script and after that the second script gets executed as a scheduled task with admin privileges. So that second script is elevated and starts Yuzu with command-line parameters and rom name. Also that second script contains the Yuzu exit script so I can exit Yuzu with Escape. All this is a bit complicated and maybe there are easier ways to accomplice the same. 

Link to comment
Share on other sites

  • 1 month later...
On 8/8/2021 at 7:35 AM, Koroth said:

No, I don't think that it has changed. But of course you don't NEED Yuzu to run as admin for it being able to run. But I have found a way to run Yuzu as admin, without UAC prompt and with an exit script. First I added an "Yuzu Admin" emulator to LaunchBox. This is just an AutoHotKey script. When I start a Switch game in LaunchBox, LaunchBox passes the rom name to this "Yuzu Admin" script. This "Yuzu Admin" script then copies the rom name to a second script and after that the second script gets executed as a scheduled task with admin privileges. So that second script is elevated and starts Yuzu with command-line parameters and rom name. Also that second script contains the Yuzu exit script so I can exit Yuzu with Escape. All this is a bit complicated and maybe there are easier ways to accomplice the same. 

@Korothcan you send the contents of your script here?

 

Edited by Aevans0001
Link to comment
Share on other sites

6 hours ago, Aevans0001 said:

can you send the contents of your script here?

The way I found to run Yuzu as admin from LaunchBox without UAC prompt is convoluted and takes a few steps.

1. Create a new text file and copy/paste the below script to that text file. Save the text file as Yuzu_Admin.ahk (so with an .ahk file extension.)

#NoEnv
#SingleInstance
SetTitleMatchMode, 2
SetWorkingDir %A_ScriptDir%

FileRead, YuzuLauncherTempFile, YuzuLauncher_Default.ahk
StringReplace, YuzuLauncherTempFile, YuzuLauncherTempFile, RomFile, %1%
FileDelete, YuzuLauncher.ahk
FileAppend, %YuzuLauncherTempFile%, YuzuLauncher.ahk

Run, C:\Windows\System32\schtasks.exe /run /tn "Yuzu Admin"
Process, Wait, yuzu.exe
Process, WaitClose, yuzu.exe
ExitApp

2. In LaunchBox create an emulator. For example Yuzu Admin. In the "Emulator Application Path" point to AutoHotkey.exe in LaunchBox\ThirdParty\AutoHotkey. In the "Default Command-line Parameters" field add the path to the Yuzu_Admin.ahk script between double quotes.

1935731515_Schermopname(108).thumb.jpg.652d15796bf087c2fd0fafb791dbb9aa.jpg

3. Create a new text file and copy/paste the below script to that text file. Save the text file as YuzuLauncher_Default.ahk (so with an .ahk file extension.) Make sure the created scripts (Yuzu_Admin.ahk and YuzuLauncher_Default.ahk) are in the same folder.

#NoEnv
#SingleInstance
SetTitleMatchMode, 3
SetWorkingDir %A_ScriptDir%
Game = RomFile

Run, %A_WorkingDir%\yuzu\yuzu-windows-msvc\yuzu.exe -f -g "%Game%"
Process, Wait, yuzu.exe
Process, WaitClose, yuzu.exe
ExitApp

$Esc::
{
WinClose, ahk_exe yuzu.exe
ExitApp
}

Before we continue, first an explanation of what the scripts do. The Yuzu_Admin.ahk we added to LaunchBox as an emulator, in the first part takes the YuzuLauncher_Default.ahk script and adds the rom name and file path then saves the script as YuzuLauncher.ahk. The second part starts the Windows Task Scheduler task we yet have to create. The by YuzuLauncher_Default.ahk script created YuzuLauncher.ahk script is what we are going to add as a Windows Task Scheduler task and is executed with admin privileges. It starts Yuzu with the -f -g command-line parameters and the path to the rom file. It also has the LaunchBox exit script for Yuzu in it.

4. Then create a Windows Task Scheduler task. I am not going in to the details right now how to create a scheduled task because I assume you know how to do that. In the "Application Path" of the task point to LaunchBox\ThirdParty\AutoHotkey\AutoHotkey.exe and in the command-line field add the path to YuzuLauncher.ahk between double quotes. (in my case "E:\LaunchBox\Emulators\Nintendo Switch\YuzuLauncher.ahk"). Make sure to tick "Run Task with highest priority". Then go back to the Yuzu_Admin.ahk script and in the line: Run, C:\Windows\System32\schtasks.exe /run /tn "Yuzu Admin" replace Yuzu Admin with the name of your task. Of course you must set up your Switch games to use the "Yuzu Admin" emulator. 

*Note*
I don't intend this write-up as a guide. More a proof of concept because in my opinion something like this is more for advanced users. The scripts reference script names: (Yuzu_Admin.ahk and YuzuLauncher_Default.ahk) so when copy/paste/saving the scripts, you HAVE to save them with those names. Anywhere a path is mentioned (in setting it up in LaunchBox or the scripts themselves), the paths must be edited to reflect your setup.
*Note 2*
All this is to run an emulator (Yuzu in this case) with Admin Privileges, no UAC prompt and still being able to exit the emulator with Escape from LaunchBox while LaunchBox provides the rom names and file paths. Because this setup right here is quite convoluted, I am curious if someone knows of an easier way.

 

*Edit*

TLDR: Add a script to LaunchBox as an emulator that passes the rom name and file paths to a second script. The second script starts the emulator with those rom names and file paths, but is added to the Windows Task Scheduler to be executed with admin privileges.

Edited by Koroth
  • Like 2
Link to comment
Share on other sites

I feel like adding one more bit of information for some further explanation. Yuzu_Admin.ahk (which I added as an emulator to LaunchBox) takes the YuzuLauncher_Default.ahk script and in the line "Game = RomFile" replaces "RomFile" with the path to your rom file. Then it saves the script as YuzuLauncher.ahk. After launching a game, YuzuLauncher.ahk would look like this:

#NoEnv
#SingleInstance
SetTitleMatchMode, 3
SetWorkingDir %A_ScriptDir%
Game = H:\Roms\Nintendo Switch\Crash Team Racing Nitro-Fueled (USA)\Crash Team Racing Nitro-Fueled.nsp

Run, %A_WorkingDir%\yuzu\yuzu-windows-msvc\yuzu.exe -f -g "%Game%"
Process, Wait, yuzu.exe
Process, WaitClose, yuzu.exe
ExitApp

$Esc::
{
WinClose, ahk_exe yuzu.exe
ExitApp
}

When launching another game, YuzuLauncher.ahk is deleted. Then Yuzu_Admin.ahk (which I added as an emulator to LaunchBox) takes the YuzuLauncher_Default.ahk script again and replaces "RomFile" with the new path to your rom file and saves it as YuzuLauncher.ahk. And so on.

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...