Jump to content
LaunchBox Community Forums

Auto Hotkey Scripts


Lordmonkus

Recommended Posts

34 minutes ago, JoeViking245 said:

Seems like there has to be a better [built-in] way to do this through the emulator settings.  I don't use M2, so I don't know.  (full screen? Probably not windowed-full screen [if even an option]).

 

Anyway, this script assumes you're running the game on your primary monitor and makes use of Windows' built-in ClipCursor function.  

Set limitW and limitH to the number of pixels you want the border to be.  "limitW" is your left/right border and "limitH" is your top/bottom border.  i.e. setting limitW to 20 puts a 20-pixel border on the left side AND on the right side (not 10 on each side).   Don't touch any other part of the script.  Pressing Escape will exit the script.

This gets the actual Width and Height of the monitor, then subtracts twice the limit from each, respectively.  Width - left & right border.  Height - top & bottom border.  Then using the ClipCursor function, confines the cursor movement to the coordinates supplied to it.  Coordinates for a monitor start in the upper left corner. 

With limitW and limitH both set to 20, the starting point from the upper left corner is 20 over and 20 down.  Then [for your monitor] from there it'll "draw the box confines", 3800 to the right, and 2120 down.

 

limitW := 20
limitH := 20

W = %A_ScreenWidth%
H = %A_ScreenHeight%
Lw := W - (limitW*2)
Lh := H - (limitH*2)

; Courtesy of:
; https://www.autohotkey.com/boards/viewtopic.php?p=180864&sid=79466bc66cbd4f6a4c02689d4fda46e7#p180864
ClipCursor(limitW,limitH,Lw,Lh)

ClipCursor(x,y:=0,w:=0,h:=0){
  static free := dllcall("User32.dll\ClipCursor", "ptr", 0)         ; Frees the mouse on script start up.
  static oe := {base:{__delete:func("clipcursor").bind("unclip")}}  ; For freeing the mouse on script exit.
  if (x = "unclip")
    return dllcall("User32.dll\ClipCursor", "ptr", 0)
	
  varsetcapacity(rect,16)
  numput(x,rect,0,"int")
  numput(y,rect,4,"int")
  numput(x+w,rect,8,"int")
  numput(y+h,rect,12,"int")
  dllcall("User32.dll\ClipCursor", "ptr", &rect)
}

esc::exitapp

 

To create/add this as an additional app, follow this:

 

Thank you so very much @JoeViking245 you are amazing man! Works like a charm! The emulator hasn't been updated since 2014 or something so it's pretty old and limited. The widescreen hacks and lua scripts plus override files by @Warped Polygon are pretty much plug and play hence I finally took the step to add this platform. Great games! Thanks again man, with your talent you help a lot of people :)

  • Like 2
Link to comment
Share on other sites

7 minutes ago, Warped Polygon said:

@Mr. RetroLust @JoeViking245 This mouse restriction issue only happens when rawinput is being used with the light gun games. I have looked into sorting this out with the M2 emu alone but there seems to be no way around it. This is a great workaround however. Can I poach this script for the next Model 2 video I do?

I turned off rawinput though and still encountered this but it could be the resolution maybe? I dont know. Be sure to add this to the start of the script btw as I got a dialog window about running the same script when starting another light gun game "#SingleInstance Force"

Edited by Mr. RetroLust
Link to comment
Share on other sites

6 minutes ago, Mr. RetroLust said:

I turned off rawinput though and still encountered this but it could be the resolution maybe? I dont know. Be sure to add this to the start of the script btw as I got a dialog window about running the same script when starting another light gun game "#SingleInstance Force"

Turning rawinput off let me navigate outside of the window, strange. I done this at various resolutions so don't think it's that. Perhaps to do with having your display or graphics card set to scale as this seems to be a factor with scaling light gun accuracy too. Need to investigate that.

  • Like 1
Link to comment
Share on other sites

18 minutes ago, Mr. RetroLust said:

Be sure to add this to the start of the script btw as I got a dialog window about running the same script when starting another light gun game "#SingleInstance Force"

If you're not using Escape to exit the game, the 'original' script is still running.  If you are, then you may need to give the esc routine a little money.

$esc::exitapp

 

If that doesn't work, remove that line altogether.  Now create another additional app to Run After that exits the above Run Before addnl. app.

If you named your Run Before script "ConfineMouseMovement.ahk", set this script to Run After.

DetectHiddenWindows, On
SetTitleMatchMode, 2
WinClose ConfineMouseMovement

 

You don't want to have to add #SingleInstance Force.  You really do want to close it when not needed.

  • Thanks 1
Link to comment
Share on other sites

1 hour ago, JoeViking245 said:

If you're not using Escape to exit the game, the 'original' script is still running.  If you are, then you may need to give the esc routine a little money.

$esc::exitapp

 

If that doesn't work, remove that line altogether.  Now create another additional app to Run After that exits the above Run Before addnl. app.

If you named your Run Before script "ConfineMouseMovement.ahk", set this script to Run After.

DetectHiddenWindows, On
SetTitleMatchMode, 2
WinClose ConfineMouseMovement

 

You don't want to have to add #SingleInstance Force.  You really do want to close it when not needed.

Thanks man! I do use your script with esc unaltered but the emulator is also using esc to quit so maybe it turns the script back on again or something?

Link to comment
Share on other sites

1 hour ago, Warped Polygon said:

Turning rawinput off let me navigate outside of the window, strange. I done this at various resolutions so don't think it's that. Perhaps to do with having your display or graphics card set to scale as this seems to be a factor with scaling light gun accuracy too. Need to investigate that.

That could be it, I also use a second (marquee) monitor so maybe that could also be a factor? Will need to check if I have scale on in gpu settings.

Link to comment
Share on other sites

21 minutes ago, Mr. RetroLust said:

Thanks man! I do use your script with esc unaltered but the emulator is also using esc to quit so maybe it turns the script back on again or something?

 

the esc key is activating a line "exitapp" which should terminate the script. but it is possible that the emulator is sort of being selfish and hogging the input in some way that the script isn't seeing the key press being sent. so you are left with the script running when you would actually want it to be closed. it's not that it's being turned back on, rather, it's never getting turned off.  adding the "$" symbol is a modifier that may fix the issue. did that solve it for you?

 

  • Thanks 1
Link to comment
Share on other sites

8 minutes ago, skizzosjt said:

 

the esc key is activating a line "exitapp" which should terminate the script. but it is possible that the emulator is sort of being selfish and hogging the input in some way that the script isn't seeing the key press being sent. so you are left with the script running when you would actually want it to be closed. it's not that it's being turned back on, rather, it's never getting turned off.  adding the "$" symbol is a modifier that may fix the issue. did that solve it for you?

 

Thanks man, thanks for explaining! I'll try it out tomorrow, evening here atm.

Link to comment
Share on other sites

15 hours ago, skizzosjt said:

 

the esc key is activating a line "exitapp" which should terminate the script. but it is possible that the emulator is sort of being selfish and hogging the input in some way that the script isn't seeing the key press being sent. so you are left with the script running when you would actually want it to be closed. it's not that it's being turned back on, rather, it's never getting turned off.  adding the "$" symbol is a modifier that may fix the issue. did that solve it for you?

 

Yes!!! The extra money for the esc did the trick, thanks @JoeViking245 and @skizzosjt :)

  • Game On 2
Link to comment
Share on other sites

@Mr. RetroLust That is what I have set also however its not that option that has an impact with the M2 emu. There should be an option just below that called 'Perform scaling on' and a choice of Display or GPU. Seems like different thing happen depending on which one is set. I'm testing this later to see if this has an impact on the cursor window restriction issue and light gun calibration scaling. I have this option set to GPU and my light gun calibration changes depending on resolution, I have been getting reports that this doesn't happen for other users, I suspect they have this option set to Display. I really want to get to the bottom of that one as I will save me time updating the configuration if accuracy can scale reliably.

  • Game On 1
Link to comment
Share on other sites

32 minutes ago, Warped Polygon said:

@Mr. RetroLust That is what I have set also however its not that option that has an impact with the M2 emu. There should be an option just below that called 'Perform scaling on' and a choice of Display or GPU. Seems like different thing happen depending on which one is set. I'm testing this later to see if this has an impact on the cursor window restriction issue and light gun calibration scaling. I have this option set to GPU and my light gun calibration changes depending on resolution, I have been getting reports that this doesn't happen for other users, I suspect they have this option set to Display. I really want to get to the bottom of that one as I will save me time updating the configuration if accuracy can scale reliably.

Thanks for researching this, let me know if I can help out in any way.

Link to comment
Share on other sites

When I running Coinops the usual alt F4 script (which I use for my other emulators) does not work when I hit the Esc key. I have a program called Super F4 which does work via the combination of Ctrl + Alt + F4. I have tried looking for a script to put in for my Coinops Emulator to enable/bind those keys to Esc but I have not had much luck. Any help would be greatly appreciated. 

Link to comment
Share on other sites

10 hours ago, OldSkool8bit said:

When I running Coinops the usual alt F4 script (which I use for my other emulators) does not work when I hit the Esc key. I have a program called Super F4 which does work via the combination of Ctrl + Alt + F4. I have tried looking for a script to put in for my Coinops Emulator to enable/bind those keys to Esc but I have not had much luck. Any help would be greatly appreciated. 

So, you use LaunchBox, to launch CoinOps, to launch games?  Seems redundant.

Anyway, to 'press' Ctrl+Alt+F4 instead of just Alt+F4 via AutoHotkey, you can use 

Send, ^!{F4}

Link to comment
Share on other sites

Awesome thank you. Yes I know about the redundancy but I was having some difficulty with the Sinden Light gun and the games which werent in MAME (MAME was easy to set up). The Coin Ops instance I am running is literally only a sinden light gun package as it has all the games I want outside of MAME preconfigured and everything so it has saved me a lot of time...everything else is straight through launchbox.

  • Game On 1
Link to comment
Share on other sites

Hi all, wondering if you can help me out in the script business :D Ive scoured the posts and i cant seem to find an answer so here goes!

I am trying to change a button for vampire survivors so it works better on my arcade cabinet But i want the script to end when the game closes. The script i have so far is this:


Run, D:\SteamLibrary\steamapps\common\Vampire Survivors\VampireSurvivors.exe

z::Enter

IfWinNotExist, Vampire Survivors
ExitApp

It launches fine, the controls are exactly what i want but i cant get the script to end and as the buttons stay changed it causes mayhem after :D

Ive also tried:

Run, D:\SteamLibrary\steamapps\common\Vampire Survivors\VampireSurvivors.exe

z::Enter

WinWaitClose, ahk_exe VampireSurvivors.exe

ExitApp



Any advice and help would be greatly appreciated, thank you :)

Ash

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