AHK

From Sinden Lightgun
Jump to navigation Jump to search

AutoHotkey (AHK) is a small but powerful automation scripting language for windows that we can use to load/call and close multiple processes from a single file.

How to Setup and use AHK

First, you need to download and Install AHK; You can download it from HERE

You install AHK much like any other windows application.


Now you are ready to create your first script!

Normally you would create a script in the root folder of the game you are using the script for, However, for the purposes of this tutorial, you will just create a script on your desktop to launch an application.


So to start with on the desktop right click your mouse and then go to "New" and the click on "Auto Hot Key Script".

This will create a new script that you can start whatever you wish with.

Now you need to edit the script. To do so, simply right-click on the new script and then open it with a text editor such as Notepad ++ (which you can download from HERE if you wish)

If you don't see a text editor in the right-click menu, select the "Open With" option and choose a text editor from the screen that pops up.


Now you are ready to start coding, But don't panic! It's not as scary as it sounds!

So now you will create the script; for this example, you will use the script to launch and close the Edge internet browser (But you can do this with any application if you dont have or want to use edge).

Firstly you need to know the file path of the application, the easy way to do this is to right-click on the application, select "Properties" and then copy the text in the "Target" text box.

It may look something like this: "C:\Program Files\Microsoft\Edge\Application\msedge.exe".


So now you can code the first line of the script; so the first line will be this:

Run, C:\Program Files\Microsoft\Edge\Application\msedge.exe


The Run command does exactly what you would think; It runs the file at the location you specified after it.


Now you will enter some more code for a keybind to close the application; This is another common snippet of code you can use AHK's while playing games.

So you will make the AHK close the Edge browser when you press the Escape button on the keyboard using the following:

Esc::                               ;EXIT BUTTON
Process,Close,msedge.exe
Run,taskkill /im "msedge.exe" /F
ExitApp
return


Now you will notice the first line has the keybind "Esc" which is the Escape button on the keyboard, You could make this any key though; for instance you may use "X" instead of Esc.

Also, take note of the Exit button text after the ; This means it's a note, and anything after the ; is ignored by AHK and is for your benefit.

The next few lines are to close and terminate the application, in this case, msedge.exe .


So you should now have a script that looks like this:

Run, C:\Program Files\Microsoft\Edge\Application\msedge.exe

Esc::                               ;EXIT BUTTON
Process,Close,msedge.exe
Run,taskkill /im "msedge.exe" /F
ExitApp
return


The script is now ready to try!

So now you go to "File" on the top menu, press "Save" and Exit the text editor.


Now double-click the new AHK script and you should see Edge load up!

If you then press the Escape key, it should then close!

Assuming this all worked correctly, congratulations, you just made and ran your first AHK script!


If you should need to edit your script for any reason, you can simply right-click on it and edit it in the text editor again.


One more thing you should be aware of is some scripts need to be run as an administrator in order to work.

To do this, you will need to compile the script first, which is very easy to do!

Simply right-click your script and click the option that says "Compile Script" this will then turn the AHK into an Executable file that can not be edited.

If you need to run it as administrator, you then simply right-click on this executable, Click "Properties", then click the "Compatibility" tab.

Under this tab, you will find a tick box at the bottom that says, "Run this program as administrator" just enable that and press "Apply".

Change DPI AHK

Script to change Res and DPI settings.(Windows 10, and Windows 7 Not tested.)

 1#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
 2SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
 3
 4#SingleInstance force 
 5
 6!#PgDn::
 7RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\ACR0408#ASNmpEVZnard_00_07DD_A1^1977EFB0FCDDA00B4A190B2C0A4C2256, DpiValue, 1
 8ChangeResolution(2560, 1440)
 9Return
10
11!#PgUp::
12RegWrite, REG_DWORD, HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\ACR0408#ASNmpEVZnard_00_07DD_A1^1977EFB0FCDDA00B4A190B2C0A4C2256, DpiValue, 0
13ChangeResolution(2560, 1440)
14Return
15
16ChangeResolution(Screen_Width := 2560, Screen_Height := 1440, Color_Depth := 32)
17{
18	VarSetCapacity(Device_Mode,156,0)
19	NumPut(156,Device_Mode,36) 
20	DllCall( "EnumDisplaySettingsA", UInt,0, UInt,-1, UInt,&Device_Mode )
21	NumPut(0x5c0000,Device_Mode,40) 
22	NumPut(Color_Depth,Device_Mode,104)
23	NumPut(Screen_Width,Device_Mode,108)
24	NumPut(Screen_Height,Device_Mode,112)
25	Return DllCall( "ChangeDisplaySettingsA", UInt,&Device_Mode, UInt,0 )
26}
27Return

This script helps change the DPI and Resolution of your monitor in windows 10. Some games need the DPI to be 100%, or the gun will not work

Let's talk through this script

  • Line 6: this is the hotkey to change enable the change (currently set to ! (ALT) + # (WinKey) + PageDown. You don't have to use a key bind to call the script. You can put it in before your load your ROM and then run the 2nd part in your exit script NOTE You need RegWrite before calling the change res.
  • Line 7: "ACR0408#ASNmpEVZnard_00_07DD_A1^1977EFB0FCDDA00B4A190B2C0A4C2256" is the name of my monitor. This will need to be changed to your monitor name. This can be found here
ChangeDPIMonitorName.png

The possible values for DPIValue are the following 0 = 100%, 1 = 125%, 2= 150%, 3= 175% and 4= 200%

  • Line 8: this is for your Resolution settings
  • Lines 11 to 14 are the same as above You need to change these settings also
  • Lines 18 to 25: you don't need to change anything here. This just changes the settings and applies them. If this isn't here, the regedit will not change anything


NOTE: If you have 2 or more monitors, you will need to choose one under HKEY_CURRENT_USER\Control Panel\Desktop\PerMonitorSettings\ and do a trial and error. I don't know how windows makes this reg folder for the display name.

Launching & Closing Sinden Software

NOTE: Tested with Sinden software v1.8

  • Enable AutoStart Sinden Lightgun on load in the Configuration tab of the Sinden software.
Process, Exist, Lightgun.exe
If (!ErrorLevel = 0) {
Process,Close,Lightgun.exe
sleep, 2000
}
Run, D:\SindenLightgun\Lightgun.exe

$Esc::
    Process,Close,Lightgun.exe
    Run,taskkill /im "Lightgun.exe" /F
    ExitApp
return