Jump to content
LaunchBox Community Forums

Auto Hotkey Scripts


Lordmonkus

Recommended Posts

@monsterm90   It worked with Notepad. ?

1st of all found the correct executable name. ("PPSSPPWindows64.exe"?) :)   But for some reason just sending Win+Shift+Left [in the script] isn't working for me.  Even if I put that first Sleep for 10 seconds.  Here's Joe's workaround for PPSSPP.  (at least it seemed to work on mu computer)

Loop
{
   IfWinActive, ahk_exe PPSSPPWindows64.exe
   {
      Sleep, 2000     ;hang out a couple seconds
      Send, !{Enter}  ;go to windowed mode
      ;Sleep, 1000	
      Send #+{Left}   ;Send Win+Shift+Left
      ;Sleep, 1000
      Send, !{Enter}  ;go back to fullscreen
      ExitApp
   }
}

Part of it I'm thinking is because it's running in fullscreen.  But once opened, you can press Win+Shift+Left and it works. 

What's worse is you can create a hotkey and THAT will work.  Here it won't Loop (wait around), but if PPSSPP is the active window and you press "Q", it'll move it over.

q::
{
   IfWinActive, ahk_exe PPSSPPWindows64.exe
   {
     Send #+{Left}
     ExitApp
   }
}


 

Link to comment
Share on other sites

18 hours ago, JoeViking245 said:

@monsterm90   It worked with Notepad. ?

1st of all found the correct executable name. ("PPSSPPWindows64.exe"?) :)   But for some reason just sending Win+Shift+Left [in the script] isn't working for me.  Even if I put that first Sleep for 10 seconds.  Here's Joe's workaround for PPSSPP.  (at least it seemed to work on mu computer)


Loop
{
   IfWinActive, ahk_exe PPSSPPWindows64.exe
   {
      Sleep, 2000     ;hang out a couple seconds
      Send, !{Enter}  ;go to windowed mode
      ;Sleep, 1000	
      Send #+{Left}   ;Send Win+Shift+Left
      ;Sleep, 1000
      Send, !{Enter}  ;go back to fullscreen
      ExitApp
   }
}

Part of it I'm thinking is because it's running in fullscreen.  But once opened, you can press Win+Shift+Left and it works. 

What's worse is you can create a hotkey and THAT will work.  Here it won't Loop (wait around), but if PPSSPP is the active window and you press "Q", it'll move it over.


q::
{
   IfWinActive, ahk_exe PPSSPPWindows64.exe
   {
     Send #+{Left}
     ExitApp
   }
}


 

yes thanks! the 1st ahk codes is works for me!

  • Game On 1
Link to comment
Share on other sites

  • 2 weeks later...

Hello, I'm looking for a script who can send a different action who depends how long you press the button

if I press 1joy11 one time , it should send ^C
if I press 1joy11 more than 2 sec , it should send ^v

it's for CITRA Save & Load last state
If it's not possible, how I can set script to say

Joy7 + Joy11 (in the same time) send ^C

Joy8 + Joy11 (in the same time) Send ^V

Thanks for your help

 

 

 

 

Edited by modhack
Link to comment
Share on other sites

1Joy11::
{
   KeyWait, Joy11, T2   ;long press ("T2" = Time 2 seconds)
   if (ErrorLevel)
   {
      Send ^V           ;long press of 1Joy11
      Sleep 500
   }
   Else
   {
      Send ^C           ;[short] press of 1Joy11
      Return
   }
}

Or your Plan "B"

1Joy11::
   If GetkeyState("Joy7")
   {
      Send ^C
      return
   }
   Else    
   If GetkeyState("Joy8")
   {
      Send ^V
      return
   }

With this one, you need to press Joy11 AFTER pressing and holding Joy7 or Joy8 respectively, in succession.

Link to comment
Share on other sites

Thanks joeVikings245 but I have no success with both scenario :( , it seems it save all the time (^c), impossible to reach the commande ^v

 

[EDIT]
OK I understand, I have another script to send ctrl+C when I press only joy11, I was not aware that it could make a conflict

not sure :/

 

 

 

Edited by modhack
Link to comment
Share on other sites

Ya, you want to setup only one set of hotkeys for the same button. :) 

Change the "C" and the "V" to lowercase "c" and "v" respectively in the code and see if that helps.  You can also shorten the duration of the 'long key press' (if you want) because in this day-and-age two seconds can actually be a really long time.

I just tested the 1st one [that uses the long-press] in Citra and it does work (at least here) for both save and load.  (didn't verify the 2nd [combo button press] though)

EDIT: Tested the combo button press using lower case "c" and "v" and it worked as well.

Edited by JoeViking245
Link to comment
Share on other sites

Hi All , I have search this thread for mentions of Keyboard2xintput AHK and found a few mentions but none to what im after or a mention to look in previous posts , i have and cant find anything,

In a  previous post i found  a user mentions k2x comes with a sample ahk ive tried editing it to best of my knowledge but since i know nothing about coding im falling short.

The Problem i am having is when i leave a game and return to bigbox my joysticks dont work because k2x is running if i turn k2x off they work.

Apparently in the sample ahk provided you can load k2x when a steam game starts and when you exit it turns off ? im unable to get that to work

Are you able to assign a button on your arcade to toggle k2s on and off what is my best options ?

 

This is the sample AHK

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

Run, "E:\bartop\software\keyboard2Xinput\keyboard2XinputGui.exe"
Run, "C:\Program Files (x86)\Steam\Steam.exe" -applaunch %1%

isRunning := "0"
While (isRunning = "0") ; Wait until the game is launched
    RegRead, isRunning, HKCU\Software\Valve\Steam\Apps\%1%, Running
    Sleep, 500

Sleep, 5000
MouseMove, 1920, 1200
WinGetTitle, Title

While (isRunning = "1") ; Wait until the game is closed
    RegRead, isRunning, HKCU\Software\Valve\Steam\Apps\%1%, Running
    Sleep, 500

; Game stopped, stop keyboard2Xinput by sending numpad multiply key (see k2x mapping.ini)
SendInput {NumpadMult}

; change focus back to Attract-Mode
WinActivate Attract-Mode

 

What ive done is edit line "E:\bartop\software\keyboard2Xinput\keyboard2XinputGui.exe" to the correct directory then copied txt

Then i  went to launchbox - Tools - Edit Autohotkey scripts for Windows Games and Pasted it in there but when i launch a steam game it wont load k2s

Any help would be much appreciated

 

 

Edited by VoidTheWolf
Link to comment
Share on other sites

8 hours ago, VoidTheWolf said:

Autohotkey scripts for Windows Games

... doesn't work for games that are launched via a Steam ID. 

Also, in your sample AHK script, the 2nd "Run" command is attempting to launch to Steam game.  So in effect, if this did work, LaunchBox would run your script which loads K2X and launches the game, then LB itself would [also] launch the game.  

It looks like the script you show is designed to be ran as an Emulator.  That is, compile the script [to an exe].  Then in LB, Add a New Emulator and point it to your compiled script.  Then for your Steam games, tell it to use this 'new' emulator.

Here's where a person smarter than myself needs to help.... you may need to edit the Application Path to the Steam game(s).  Mine all say something like

steam://rungameid/818320

From your 2nd Run command which uses a command line to launch the game, it may only want the Steam's game ID #.  (v.s. the whole line shown above).  So in my case

Run, "C:\Program Files (x86)\Steam\Steam.exe" -applaunch %1%

;...would become....

Run, "C:\Program Files (x86)\Steam\Steam.exe" -applaunch steam://rungameid/818320

;...but might need to be simply...

Run, "C:\Program Files (x86)\Steam\Steam.exe" -applaunch 818320

To clarify, I'm not saying edit the script.  I'm saying you may need to edit the Application Paths for the games.  The compiled script with automatically change %1% to whatever is in the games Application Path.  Be it "steam://rungameid/818320", or simply "818320".

  • Like 1
Link to comment
Share on other sites

@VoidTheWolf  Being the person I am, I just had to test this. :)  Short story, works GREAT!  Granted I did NOT test with K2X or any secondary app/program, but the launching of a Steam game, waiting for it to exit/quit, then do something else does work.  (tested using a simple message box)

#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.

Run, "E:\bartop\software\keyboard2Xinput\keyboard2XinputGui.exe"      ;**** Verify Path ****
Run, "C:\Program Files (x86)\Steam\Steam.exe" -applaunch %1%          ;**** Verify Path ****

isRunning := "0"
While (isRunning = "0") ; Wait until the game is launched
    RegRead, isRunning, HKCU\Software\Valve\Steam\Apps\%1%, Running
    Sleep, 500

Sleep, 5000
MouseMove, 1920, 1200
WinGetTitle, Title

While (isRunning = "1") ; Wait until the game is closed
    RegRead, isRunning, HKCU\Software\Valve\Steam\Apps\%1%, Running
    Sleep, 500

; Game stopped, stop keyboard2Xinput by sending numpad multiply key (see k2x mapping.ini)
; MsgBox, Game Exited
SendInput {NumpadMult}

The last 2 lines that were in your code aren't necessary for LaunchBox.  The 2nd to last line I have here was my test to verify that it indeed did wait until the game exited before continuing on.

If your Steam games' Application Path uses the Steam's game ID such as "steam://rungameid/818320", that WILL work as is.  So the only thing you'll need to do for the games is to have them use an emulator (the compiled script).

When you add the new Emulator, be sure to CHECK both the "Don't use quotes" and the "Use file name only" boxes. I don't think the Quotes one actually matters, but the Use File Name Only definitely does.image.thumb.png.99729da336d0908be1408ba5186667b9.png

And of course, under Associated Platforms, add Steam.  If ALL your Steam games will use K2X, check the box for Default Emulator.image.thumb.png.4b4a7d87c47e0bddaa67fdf6125d7f6d.png 

  • Thanks 1
Link to comment
Share on other sites

I didn't see anyone else having this issue so I wasn't sure if it was just me, but when opening a game with Nebula's Sega Model 2 emulator the window border was still visible. I added the following snippet to the "Running Autohotkey Script" tab for the emulator. This will maximize the window so a true full screen is shown. 

; This section maximizes the game window on startup
Sleep, 500
Send {LWin down} {Up} {LWin up}
Return

 

  • Like 1
Link to comment
Share on other sites

@JoeViking245 Finally got to test it today and worked 100% whoooo hoooo  thanks heaps again :)

 

For fellow Noobs 

Step 1. remove this code that @JoeViking245 added to test for me           ; MsgBox, Game Exited

Step 2. Edit this line "E:\bartop\software\keyboard2Xinput\keyboard2XinputGui.exe"  and add your dir for k2x executable

Step 3 . Install Autohotkey program it installs a program with it called .ahkto.exe  run that and point to your notepad file with the ahk script , hit convert to .exe

Step 4. Add as steam emulator as @JoeViking245 has guided above

 

Hope ive simplified it even further for future noobs :)

 

  • Like 1
Link to comment
Share on other sites

Once again sorry if this is around but I didn't see it when looking. I run Flycast standalone outside of Retroarch. In order for escape to work for exiting games you will need to use the following auto hotkey script. Note: this is this is just a copy and paste from the M2 emulator script but figured if I can make life easier for someone looking around might as well. Cheers all!

; This section closes Sega Model 2 Emulator when pressing Escape
$Esc::
{
	Process, Close, {{{StartupEXE}}}
}

 

Link to comment
Share on other sites

12 minutes ago, hodgegoulashi said:

Once again sorry if this is around but I didn't see it when looking. I run Flycast standalone outside of Retroarch. In order for escape to work for exiting games you will need to use the following auto hotkey script. Note: this is this is just a copy and paste from the M2 emulator script but figured if I can make life easier for someone looking around might as well. Cheers all!


; This section closes Sega Model 2 Emulator when pressing Escape
$Esc::
{
	Process, Close, {{{StartupEXE}}}
}

 

It been long recommended to no longer use Process, Close as it is a hard close script. The script below if better to use.

I know by default LB puts the Process, Close script in a few emulators and I have asked Jason if we can update LB with the better code.

; This section closes emulator when pressing Escape
$Esc::
{
	WinClose, ahk_exe {{{StartupEXE}}}
}

 

  • Unusual Gem 1
Link to comment
Share on other sites

Join the conversation

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

×
×
  • Create New...