Autofire toggle using Keyboard or Game Controller (can be used for Game Emulators Speed Toggle)

Post gaming related scripts
ahk1
Posts: 9
Joined: 24 Sep 2020, 07:12

Autofire toggle using Keyboard or Game Controller (can be used for Game Emulators Speed Toggle)

Post by ahk1 » 24 Sep 2020, 07:42

Autofire toggle using Keyboard or Game Controller (can be used for Game Emulators Speed Toggle)

This script enables custom keyboard keys and/or custom game controller Thumbsticks or buttons to toggle the state of a key between being kept pressed (and autofiring) and being released.
The script has the advantage that you can use the game controller buttons and thumbsticks for the toggle.

E.g.:

Left Thumbstick moved to left and release - start autofire
Left Thumbstick moved again to left and released - stop autofire
Left Thumbstick moved again to left and released - start autofire , etc. ...

Left Thumbstick moved to right and released - only stops the autofire (chosen by me instead of toggle)


Save the code for the script as a .ahk file. For example save it as AutoHotkey.ahk in the folder where you have AutoHotkey.exe .

Custom Keys used (you can change them) :

The toggle for the key autofire (used by me for speed toggle) is caused by:
a) - Pressing any of these keyboard keys or the controller buttons:
Up Arrow key, L1 controller button, R1 controller button

b) - Moving the Thumbstick:
Toggle a custom key autofire (Toggle speed increase for example) - by moving the game controller Left_Thumbstick to the left, starting from the rest(center) position
If you move the Left Thumbstick to the left and release it tho the center position, the key starts to autofire,
then if you move it again to the left and release it, the key state will toggle and it will stop the autofire by being in the released (not pressed) position.

c)
Pressing these keys will stop the autofire (can be changed):
Down Arrow, f, r, t, b, Shift, Cross (or X) key on the controller, Circle key on the controller, Square key on the controller, Triangle key on the controller



I tested the script on Windows 7 x64, Autohotkey v1.1.24.01, Sony Dualshock 4 controller with DS4Windows and the game emulators: PPSSPP 1.8.0 (PSP Emulator) and BizHawk (multi-platform Emulator: PlayStation 1, Game Boy Advance, etc)


Some game emulators can be customized to have a speed toggle assigned to a key.
The problem is that you have to keep the key pressed in order for the game speed to be high.
This Autohotkey script creates a toggle for the key, so that you can press a button and the speed key will be kept in the pressed position automatically.


The script also detects if a Game Controller is connected.
The script also detects if the mouse was clicked outside the game emulator window (or the software you use the script for, if you change the code for it) and then it stops the speed increase and resets the toggled state of the Speed key (Up arrow).
The same thing happens if the game emulator window looses focus, for example by using Alt+Tab.






You cannot use code or the parts of any algorithm from this file for commercial purposes, so you are not allowed by me, the author, to make money from this code.
If you add code from this script to another file, you have to specify there for other people to see, that the lines of code inspired from my script are not for commercial purposes.



Code: Select all


; Autofire toggle using Keyboard or Game Controller (can be used for Game Emulators Speed Toggle)


; You cannot use code or the parts of any algorithm from this file for commercial purposes, so you are not allowed by me, the author, to make money from this code.
; If you add code from this script to another file, you have to specify there for other people to see, that the lines of code inspired from my script are not for commercial purposes.





; Script Description:
;
; tested with Autohotkey v1.1.24.01
; The code uses custom keyboard keys and/or custom game controller Thumbsticks or buttons to toggle the state of a key between being kept pressed (and autofiring) and being released.
; You can use to code to autofire a key for other software, not just game emulators.
; The script has the advantage that you can use the game controller buttons and thumbsticks for the toggle.
; You can edit Autohotkey scripts with the AutoHotkey editor named SciTE4AutoHotkey(Based on SciTE). It has good code folding for ahk scripts.





; How to use the Keyboard and Game Controller :
;
; Press a key or a controller thumbstick to toggle the autofire.
;
; Custom Keys used (You can change them) : 
;
; The toggle for the key autofire (used by me for speed toggle) is caused by:
; a) - Pressing any of these keyboard keys or the controller buttons:
;      Up Arrow key, L1 controller button, R1 controller button
;
; b) - Moving the Thumbstick:
   ; Toggle a custom key autofire (Toggle speed increase for example) - by moving the game controller Left_Thumbstick to the left, starting from the rest(center) position
   ; If you move the Left Thumbstick to the left and release it tho the center position, the key starts to autofire,
   ; then if you move it again to the left and release it, the key state will toggle and it will stop the autofire by being in the released (not pressed) position.
;
; Because I wanted some more variety, moving the Left Thumbstick to the right doesn't act like a toggle, it only stops the autofire, it cannot start the autofire
; You can make the movement of the Left Thumbstick to the right to do the same thing as the movement of the Left Thumbstick to the left by modifying the script
; I also made some keys or buttons to act as a stop autofire not as a toggle, for different reasons.
; Pressing these keys will stop the autofire:
;      Down Arrow, f, r, t, b, Shift, Cross (or X) key on the controller, Circle key on the controller, Square key on the controller, Triangle key on the controller 
;
; E.g.:
;
; Left Thumbstick moved to left and released - start autofire
; Left Thumbstick moved again to left and released - stop autofire
; Left Thumbstick moved again to left and released - start autofire , etc. ...
;
; Left Thumbstick moved to right and released - only stops the autofire (chosen by me instead of toggle)
; I used it with game emulators for speed key toggle.







; Errata:
;
; Because Autohotkey uses the word Joy for the game controller Thumbstick, I used the word JOYSTICK instead of thumbstick inside the script, so the code is not for a joystick but for a game controller.





; How to use the script:
;
; Some game emulators can be customized to have a speed toggle assigned to a key.
; The problem is that you have to keep the key pressed in order for the game speed to be high.
; This Autohotkey script creates a toggle for the key, so that you can press a button and the speed key will be kept in the pressed position automatically.
; The following usage of the toggle will disable the speed increase by restoring the key to the released position.
;
;
; For example I use the Up arrow key inside the game emulator's custom keyboard assignment window and I assign the Up arrow key to be the speed increase key.
;
; With this script, by pressing custom keyboard keys and/or game controller keys or using the analog thumbsticks, you can make the Up Arrow key (or any other key, by modifying this script) to be toggled between a state where it is pressed continuously and the state were is released.
;
; You can also use this script to toggle the autofire of other key instead of the Up arrow key, by using a Game controller or the keyboard.







; Software Used:

; I tested the script on Windows 7 x64, Autohotkey v1.1.24.01, Sony Dualshock 4 controller with DS4Windows and the game emulators: PPSSPP 1.8.0 (PSP Emulator) and BizHawk (multi-platform Emulator: PlayStation 1, Game Boy Advance, etc)

; 1)
; Net Framework Requirements:
;    MicRooCerAut2011_2011_03_22.crt , with md5: ce0490d5e56c34a5ae0be98be581185d
;       Install MicRooCerAut2011_2011_03_22.crt in the Trusted Root Certification Authorities group by right clicking on the file and following the UI prompts.
;       Download MicRooCerAut2011_2011_03_22.crt from: http://www.microsoft.com/pki/certs/MicRooCerAut2011_2011_03_22.crt

; 2)
; DS4Windows 1.7.8
;
; DS4windows requires:
;    - Microsoft .Net Framework 4.6.2 (or later).

;    - ViGEmBus_Setup_1.16.116.exe , with md5: d39b08374649c0bee1b78c1cee234fe7

;    - Xbox 360 Controller for Windows 7 x64 - Xbox360_64Eng.exe , with md5: 4c7fbad5bbebc0d3807129092a1de4b9

;    - Microsoft Visual C++ 2015-2019 Redistributable x64 and x86:
;        - Visual C++ 2015-2019 Redistributable VC_redist.x86.exe , with md5: de34b1c517e0463602624bbc8294c08d
;        - Visual C++ 2015-2019 Redistributable VC_redist.x64.exe , with md5: f0248d477e74687c5619ae16498b13d4











; Details:
;
; The script also detects if a Game Controller is connected.
; The script also detects if the mouse was clicked outside the game emulator window and then it stops the speed increase and resets the toggled state of the Speed key (Up arrow).
; The same thing happens if the game emulator window looses focus, for example by using Alt+Tab.

; The script detects if a game controller is connected starting from the line:
; if ("" . JoyX != "")
; This is needed because the controller can get disconnected and the custom key will keep firing so the speed increase cannot be stopped by reconnecting the controller; you will have to restart the game emulator.
; The game controller detection code fixes this problem (but it means that this code needs to be put at the top of the Autohotkey file).


; I included the toggle code for 2 emulators because it is a little tricky to figure out how to use the code for more than 1 emulator, given that Autohotkey is a pretty peculiar programming language.

; Because Autohotkey is peculiar, I included in the script extra Autohotkey code that is not needed for the speed toggle for people to see how they can use this code with Autohotkey code for other software - to see the different blocks of code that are needed or not, look inside the file for the words: NEEDED FOR THE SPEED TOGGLE

; The problem was that you have to put the part of the code for the Speed toggle that uses the Game controller, at the top of the Autohotkey file - in order for Autohotkey to run well for other software too.
; So adapting the code for a Game Controller was a little tricky and you had to put the code for the Game Controller before other code.

; The code for the 2 emulators is basically the same.









Menu, Tray, Icon




; Because Autohotkey uses the word Joy for the game controller Thumbstick, I used the word JOYSTICK instead of thumbstick inside the script, so the code is not for a joystick but for a game controller.


; PLACE THE JOYSTICK FUNCTIONS BEFORE ANY KEY REMAP IF USING LOOPS OR WatchAxis









;-------------------------; GLOBAL VARIABLES = USE THEM BEFORE YOU DECLARE ANY KEY
;
;https://autohotkey.com/board/topic/48488-solved-initializing-a-global-variable/
;From reading your post, I believe you are confusing global variables with variables that are set in the auto executable section of the script :wink: .
;The section before the first hotkey will execute each time the script is run. All variables in that section will be set.
;Variables that first occur after a hotkey will only be set when that code runs (if you try to set a variable between hotkeys, that code will never run :O).
;Global variables would be the counter part of local variables (ie - variables that are used in a function).
;In fact, I believe the keyword "global" can only be used in functions. Hope that helps. 
;
;--------------------------------------------------------------------------------

Mesen_Toggle := 0

Nestopia_Run_Toggle := 0

PPSSPP_Speed_Toggle := 0
BizHawk_Speed_Toggle := 0   ; BizHawk_Speed_Toggle init value doesn't matter, its value will be changed




; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!        IF YOU PUT THE CODE LIKE THe FOLLOWING 3 LINES, BEFORE THE JOYSTICK CODE SECTION, THE SCRIPT WILL NOT WORK
;                                                     I THINK THIS IS BECAUSE OF HOW AUTOHOTKEY WORKS. THE CODE IS COMMENTED SO THAT THE SCRIPT WILL WORK. DON'T UNCOMMENT THESE 3 LINES ABOUT IRFANVIEW
;~ GroupAdd, IrfanView_Group, ahk_class IrfanView
;~ GroupAdd, IrfanView_Group, ahk_class FullScreenClass
;~ return







; THE FOLLOWING CODE LINES ARE NOT NEEDED FOR THE SPEED TOGGLE, I PUT THIS IN ORDER FOR YOU TO SEE HOW TO USE THE SCRIPT CODE WITH OTHER PROGRAMS- i.e. the next lines for testing if specific windows/programs are open


;-------------------------; Test if specific windows/programs are open
;
;
;--------------------------------------------------------------------------------


; "if WinExist(my_title)" does not work well with  "WinGetTitle, my_title, ahk_class PPSSPPWnd" if the PPSSPPWnd is not opened and so the my_title will be an empty string.
; WinExist will have an empty string as parameter and the if statement will still be executed when it should not be.





; PPSSPP - PSP Emulator

if WinExist("ahk_exe PPSSPPWindows64.exe")   ; PSP resolution = 480 x 272  
{

    PPSSPP_window_width_margins := 16
    PPSSPP_window_height_margins := 58

    my_win_scaling_f := 2.5
    PSP_Horiz_res := 480
    PSP_Vert_res := 272


    WinActivate  ; Automatically uses the window found above.
    WinGetPos, myX, myY, myWindow_Width, myWindow_Height
    ;MsgBox, x: %myX%, Y: %myY%, window Width: %myWindow_Width%, window Height: %myWindow_Height%

    ; Scale the PPSSPP window
    WinMove, PPSSPP v1.8.0, , myX, myY, my_win_scaling_f * PSP_Horiz_res + PPSSPP_window_width_margins, my_win_scaling_f * PSP_Vert_res + PPSSPP_window_height_margins

    ; Verify results:
    ;WinGetPos, myX, myY, myWindow_Width, myWindow_Height, PPSSPP v1.8.0
    ;MsgBox, x: %myX%, Y: %myY%, window Width: %myWindow_Width%, window Height: %myWindow_Height%
}








; THE FOLLOWING CODE IS NEEDED FOR THE SPEED TOGGLE



;-------------------------; Joystick settings for Emulators
;
;--------------------------------------------------------------------------------


; PLACE THE JOYSTICK FUNCTIONS BEFORE ANY KEY REMAP IF USING LOOPS OR WatchAxis



JoyX_has_Reset_BizHawk := 0
JoyX_has_Reset_PPSSPP := 0
BizHawk_Speed_Toggle_Joy := 0
BizHawk_Speed_Toggle := 0

PPSSPP_Speed_Toggle_Joy := 0
PPSSPP_Speed_Toggle := 0






; The Thumbstick speed toggle only works for the window that has the first WatchAxis loop.
; The Thumbstick (Joystick controls) speed toggles  for the following WatchAxis loops don't work.


GroupAdd, Group_game_speed_toggle, ahk_exe PPSSPPWindows64.exe
GroupAdd, Group_game_speed_toggle, ahk_exe EmuHawk.exe



#IfWinActive ahk_group Group_game_speed_toggle
{



   ; Joystick settings for Final Fantasy IX using the BizHawk emulator (EmuHawk.exe is the executable)
   ; and Joystick settings for Final Fantasy Tactics using the PPSSPP emulator


   ; !!!!!!!!!!!!!!!!!!!!!!
   ;
   ;
   ; If any keys are remapped before WatchAxis or any loop, then WatchAxis or the loops will not work unless you used them inside a key redefinition
   ; WatchAxis works Only if it is inside the first #IfWinActive region without other keys being remapped before it, or it is before the others #IfWinActive regions where keys are remapped.
   ; The place where you remap a key marks the non-auto-execute section of the script
   ;
   ;
   ;
   ; A loop runs only in the autohotkey.ahk script's auto-execute section, and the auto-execute section stops when there is a return, 
   ; a hotkey or a hotstring maybe more things but at least those stop the auto-executing of the script and puts the script in to an idle state
   ; so the loop needs to be inside a key remap to work in the non-auto-execute section of the script.
   ;
   ; !!!!!!!!!!!!!!!!!!!!!!


         ; A value of 0 causes the joystick number to be auto-detected
         ;JoystickNumber = 0


         ; Auto-detect the joystick number if called for:
         ;if JoystickNumber <= 0
         ;{
         ;	Loop 16  ; Query each joystick number to find out which ones exist.
         ;	{
         ;		GetKeyState, JoyName, %A_Index%JoyName
         ;		if JoyName <>
         ;		{
         ;			JoystickNumber = %A_Index%
         ;			break
         ;		}
         ;	}
         ;	if JoystickNumber <= 0
         ;	{
         ;		;Tooltip, The system does not appear to have any joysticks.
         ;	
         ;	}
         ;	;else Tooltip, Joystick detected
         ;}





         ; You can use a loop(which includes Sleep, 100) instead of SetTimer
         ;Loop
         ;{
         ; Sleep, 100


   #Persistent  ; Keep this script running until the user explicitly exits it.
   SetTimer, WatchAxis1, 100
   return


;--------------------------------------------------------------------------------
;
;--------------------------------------------------------------------------------


   WatchAxis1:

      GetKeyState, JoyX, 1JoyX
      ;ToolTip, JoyX value: %JoyX%
      ;Sleep 800

      ;if ("" . JoyX == "")
      ;{   ToolTip, `r`nJoystick not present`r`n ` `r`nJoyX value: %JoyX% `r`nJoyX value: Null`r`n `
      ;}
      ;else
      ;{   ToolTip, JoyX value: %JoyX% `,`r`njoystick present 
      ;}


     
      if ("" . JoyX != "")
      {

         ; You must make sure that during the time when the Left Joystick is on the left side, the movement is not continuously being interpreted
         ; You only want the Left Joystick movement to be interpreted when you start an action, not continuously during the movement of the joystick
         ; that is why JoyX_has_Reset_BizHawk has many values and is used to check if the Left Joystick has been moved to the left once, has returned from the first left movement
         ; JoyX_has_Reset_BizHawk means the Left Joystick was moved left once and moved back to the center position , so its position was reset
         ; When the Left Joystick comes back in the center position for the firs time, we have JoyX_has_Reset_BizHawk := 2

         ; I also set the Left Joystick move left to start the speed increase (so it works as a toggle for the speed increase)


         ; BizHawk_Speed_Toggle shows when the speed increase is initiated by pressing the Up arrow key
         ; BizHawk_Speed_Toggle_Joy shows when the speed increase is initiated by moving to the left the Left Thumbstick of the Dualshock 4/Xbox controller


         ; use BizHawk_Speed_Toggle to check if the speed increase was initiated first by pressing the Up arrow key




; FIRST GAME EMULATOR JOYSTICK LOOP *******************************************************************


         ; when the joystick is present, run the while loop that increases the game speed (by continuously pressing the Up arrow button) only if the active window is the game window
         ; while loop is given by: While (BizHawk_Speed_Toggle_Joy == 1) 
         ; game window is given by: If WinActive("ahk_class WindowsForms10.Window.8.app.0.ffe60_r12_ad1")

         If WinActive("ahk_class WindowsForms10.Window.8.app.0.ffe60_r12_ad1")
         {


            ; Disable the speed increase started by the Up arrow key - first part
            ; This is done in multiple parts because we don't want the Joystick position to be interpreted when is in the left position
            ; We want only the different states of the Joystick position to matter, not the transitions between the states.
    
            if (JoyX <= 45.0 && JoyX_has_Reset_BizHawk == 0 && BizHawk_Speed_Toggle == 1 )
            {
               ;Tooltip, 03_ <45: - BizHawk_Speed_Toggle_Joy: %BizHawk_Speed_Toggle_Joy%`nJoyX_has_Reset_BizHawk: %JoyX_has_Reset_BizHawk%
               ;Sleep, 900
    
               Send {Up up}
               Sleep 50
    
               ; JoyX_has_Reset_BizHawk is reset in two states, first in this if clause and then in the next if clause, to prevent collision with other cases
               JoyX_has_Reset_BizHawk := 1
            }
    
    
            ; Disable the speed increase started by the Up arrow key - second part
            if (JoyX>=49 and Joyx <=50.5 && JoyX_has_Reset_BizHawk == 1 && BizHawk_Speed_Toggle_Joy == 0)
            {
               ;Tooltip, 04_ <45: - BizHawk_Speed_Toggle_Joy: %BizHawk_Speed_Toggle_Joy%`nJoyX_has_Reset_BizHawk: %JoyX_has_Reset_BizHawk%
               ;Sleep, 900
    
               JoyX_has_Reset_BizHawk := 0
    
               ; We stop the speed toggle initiated by the Up arrow key and reset its variable that shows when the speed toggle is initiated
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }
    
    
    
               ; If the speed toggle was Not initiated (by the Up arrow key)
               ; use Left Joystick move left to start the speed increase - Move Left Joystick once to the left to start the speed increase (i.e. start the speed increase)
    
               if (JoyX <= 45.0 && JoyX_has_Reset_BizHawk == 0 && BizHawk_Speed_Toggle != 1 )
               {
    
                  JoyX_has_Reset_BizHawk := 1
    
                  ;ToolTip, JoyX: %JoyX%
    
                  ;ToolTip, JoyX <= 45.0 && JoyX_has_Reset_BizHawk == 0 && BizHawk_Speed_Toggle != 1
                  ;Sleep, 1200
    
    
                  BizHawk_Speed_Toggle_Joy := 1
    
    
                  ;Tooltip, 1_ <= 45.0 && JoyX_has_Reset_BizHawk == 0`nStart Speedup -  BizHawk_Speed_Toggle_Joy: %BizHawk_Speed_Toggle_Joy%`nJoyX_has_Reset_BizHawk: %JoyX_has_Reset_BizHawk% 
                  ;Sleep, 1500
    
    
    
    
               ; Send {Up down} - Send Up arrow keystrokes as long as BizHawk_Speed_Toggle_Joy == 1
    
               While (BizHawk_Speed_Toggle_Joy == 1)
               {
    
                  If WinActive("ahk_class WindowsForms10.Window.8.app.0.ffe60_r12_ad1")
                  {
                     ;ToolTip, JoyX_has_Reset_BizHawk: %JoyX_has_Reset_BizHawk% `r`nJoyX: %JoyX%
                     ;Sleep, 2300
    
                     Send {Up down}
                     Sleep, 120   ; or Sleep, 210
    
    
                     GetKeyState, JoyX, 1JoyX
    
    
         
                     ; use Left Joystick move left to disable the speed increase
         
                     if (JoyX>=49 and Joyx <=50.5 &&  JoyX_has_Reset_BizHawk == 1)
                     {
                        JoyX_has_Reset_BizHawk := 2
    
                        ;Tooltip, 2_ >=49 && <=50.5: BizHawk_Speed_Toggle_Joy: %BizHawk_Speed_Toggle_Joy%`nJoyX_has_Reset_BizHawk: %JoyX_has_Reset_BizHawk%
                        ;Sleep, 1500
                     }
    
    
    
                     ; use Left Joystick move left to disable the speed increase - The Left Joystick was reset to the center position after being moved left to start the speed increase and now is moved again to the left to stop the speed increase
                     if (JoyX <= 45.0 && JoyX_has_Reset_BizHawk == 2)
                     {
    
                        JoyX_has_Reset_BizHawk := 3
    
                        ;Tooltip, 3_ <45: - BizHawk_Speed_Toggle_Joy: %BizHawk_Speed_Toggle_Joy%`nJoyX_has_Reset_BizHawk: %JoyX_has_Reset_BizHawk%
                        ;Sleep, 1500
                     }
    
    
    
                             
                     if (JoyX>=49 and Joyx <=50.5 && JoyX_has_Reset_BizHawk == 3)
                     {
                                 
                        Send {Up up}
                        Sleep 50
    
                        BizHawk_Speed_Toggle_Joy := 0
                        JoyX_has_Reset_BizHawk := 0
    
                        ;Tooltip, 0_ Full reset: - BizHawk_Speed_Toggle_Joy: %BizHawk_Speed_Toggle_Joy%`nJoyX_has_Reset_BizHawk: %JoyX_has_Reset_BizHawk%
                        ;Sleep, 1500
                     }
    
    
    
    
    
                     ;Send {Up up} toggles the speed increase
    
                     ; use the Down arrow key for to change the game to normal speed and disable the speed increase
                     
                     if ( GetKeyState("Down", "p") == True)
                     {
                        BizHawk_Speed_Toggle := 0
                        Send {Up up}
                        JoyX_has_Reset_BizHawk := 3   ; needed for the functionality - use Left Joystick move left to disable the speed increase
                     }
    
    
    
                     ; if the left mouse is pressed (for example to click the PPSSPP menu), disable the speed increase
                     ; it doesn't work very well wen clicking on the menu items instead of the main window
                     LButton_State_Joy := GetKeyState("LButton", "p")
                     RButton_State_Joy := GetKeyState("RButton", "p")
             
                     if ( LButton_State_Joy == True or RButton_State_Joy == True)
                     {
                        BizHawk_Speed_Toggle := 0
                        Send {Up up}
                        JoyX_has_Reset_BizHawk := 3   ; needed for the functionality - use Left Joystick move left to disable the speed increase
                     }
    
    
    
                     ; You may also want to use the v key in the emulator controller mapping settings, for the x (cross) button on the controller for selecting - disable speed increase if v is pressed
    
                    ; use the f key  - disable speed increase if v is pressed
                    if ( GetKeyState("f", "p") == True)
                    {
                        BizHawk_Speed_Toggle := 0
                        Send {Up up}
                        JoyX_has_Reset_BizHawk := 3   ; needed for the functionality - use Left Joystick move left to disable the speed increase
                    }
    
                    ; use the b key for the O (circle) button on the controller for selecting - disable speed increase if b is pressed
    
                    if ( GetKeyState("b", "p") == True)
                    {
                        BizHawk_Speed_Toggle := 0
                        Send {Up up}
                        JoyX_has_Reset_BizHawk := 3   ; needed for the functionality - use Left Joystick move left to disable the speed increase
                    }
    
    
    
                    ; use the Cross (or X) key on the controller to change the game to normal speed and disable the speed increase
    
                    if ( GetKeyState("joy1", "p") == True)
                    {
                        BizHawk_Speed_Toggle := 0
                        Send {Up up}
                        JoyX_has_Reset_BizHawk := 3   ; needed for the functionality - use Left Joystick move left to disable the speed increase
                    }
    
    
    
                    ; use the Circle key on the controller to change the game to normal speed and disable the speed increase
    
                    if ( GetKeyState("joy2", "p") == True)
                    {
                        BizHawk_Speed_Toggle := 0
                        Send {Up up}
                        JoyX_has_Reset_BizHawk := 3   ; needed for the functionality - use Left Joystick move left to disable the speed increase
                    }
    
    
                    ; use the Square key on the controller to change the game to normal speed and disable the speed increase
    
                    if ( GetKeyState("joy3", "p") == True)
                    {
                        BizHawk_Speed_Toggle := 0
                        Send {Up up}
                        JoyX_has_Reset_BizHawk := 3   ; needed for the functionality - use Left Joystick move left to disable the speed increase
                    }
    
    
    
    
    
                    ; use the Triangle key on the controller to change the game to normal speed and disable the speed increase
    
                    if ( GetKeyState("joy4", "p") == True)
                    {
                        BizHawk_Speed_Toggle := 0
                        Send {Up up}
                        JoyX_has_Reset_BizHawk := 3   ; needed for the functionality - use Left Joystick move left to disable the speed increase
                    }
    
    
    
 
                    ; the Shift key is used in combination with other key to save the game - disable speed increase if the Shift key is pressed
    
                    if ( GetKeyState("Shift", "p") == True)
                    {
                        BizHawk_Speed_Toggle := 0
                        Send {Up up}
                        JoyX_has_Reset_BizHawk := 3   ; needed for the functionality - use Left Joystick move left to disable the speed increase
                    }



   
                     ; use Left Thumbstick move right to disable the speed increase started by moving the Left Thumbstick to the left
    
                     if JoyX >= 55.0
                     {
                        Send {Up up}
                        Sleep 50
    
                        BizHawk_Speed_Toggle_Joy := 0
                        JoyX_has_Reset_BizHawk := 0
                     }
    
    
    
    
                  }   ; end for If WinActive("ahk_class WindowsForms10.Window.8.app.0.ffe60_r12_ad1")
    
    
    
                  ; stop the automatic key press if the focus is moved  to another application window
                  else
                  {
                     BizHawk_Speed_Toggle := 0
                     Send {Up up}
                     JoyX_has_Reset_BizHawk := 0
                     BizHawk_Speed_Toggle_Joy :=0
                  }
    
    
    
    
               } ; end> While (BizHawk_Speed_Toggle_Joy == 1)
    
    
            } ; end> if (JoyX <= 45.0 && JoyX_has_Reset_BizHawk == 0 && BizHawk_Speed_Toggle != 1 )


         }   ; end> If WinActive("ahk_class WindowsForms10.Window.8.app.0.ffe60_r12_ad1")





; ANOTHER GAME EMULATOR JOYSTICK LOOP *******************************************************************





         ; PPSSPP_Speed_Toggle shows when the speed increase is initiated by pressing the Up arrow key
         ; PPSSPP_Speed_Toggle_Joy shows when the speed increase is initiated by moving to the left the Left Thumbstick of the Dualshock 4/Xbox controller


         ; use PPSSPP_Speed_Toggle to check if the speed increase was initiated first by pressing the Up arrow key


;         ; use Left Thumbstick move right to disable the speed increase started by the Up arrow button
;         if JoyX >= 55.0
;         {
;            Send {Up up}
;            Sleep 50
;
;            JoyX_has_Reset_PPSSPP := 0
;            PPSSPP_Speed_Toggle := 0
;         }




         ; when the joystick is present, run the while loop that increases the game speed (by continuously pressing the Up arrow button) only if the active window is the game window
         ; while loop is given by: While (PPSSPP_Speed_Toggle_Joy == 1) 
         ; game window is given by: If WinActive("ahk_class PPSSPPWnd")

         If WinActive("ahk_class PPSSPPWnd")
         {
   
            ; Disable the speed increase started by the Up arrow key - first part
            ; This is done in multiple parts because we don't want the Joystick position to be interpreted when is in the left position
            ; We want only the different states of the Joystick position to matter, not the transitions between the states.
   
            if (JoyX <= 45.0 && JoyX_has_Reset_PPSSPP == 0 && PPSSPP_Speed_Toggle == 1 )
            {
               ;Tooltip, p03_ <45: - PPSSPP_Speed_Toggle_Joy: %PPSSPP_Speed_Toggle_Joy%`nJoyX_has_Reset_PPSSPP: %JoyX_has_Reset_PPSSPP%
               ;Sleep, 900
   
               Send {Up up}
               Sleep 50
   
               ; JoyX_has_Reset_PPSSPP is reset in two states, first in this if clause and then in the next if clause, to prevent collision with other cases
               JoyX_has_Reset_PPSSPP := 1
            }
   
   
            ; Disable the speed increase started by the Up arrow key - second part
            if (JoyX>=49 and Joyx <=50.5 && JoyX_has_Reset_PPSSPP == 1 && PPSSPP_Speed_Toggle_Joy == 0)
            {
               ;Tooltip, p04_ <45: - PPSSPP_Speed_Toggle_Joy: %PPSSPP_Speed_Toggle_Joy%`nJoyX_has_Reset_PPSSPP: %JoyX_has_Reset_PPSSPP%
               ;Sleep, 900
   
               JoyX_has_Reset_PPSSPP := 0
   
               ; We stop the speed toggle initiated by the Up arrow key and reset its variable that shows when the speed toggle is initiated
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }
   
   
   
            ; If the speed toggle was Not initiated (by the Up arrow key)
            ; use Left Joystick move left to start the speed increase - Move Left Joystick once to the left to start the speed increase (i.e. start the speed increase)

            if (JoyX <= 45.0 && JoyX_has_Reset_PPSSPP == 0 && PPSSPP_Speed_Toggle != 1 )
            {

               JoyX_has_Reset_PPSSPP := 1

               ;ToolTip, pJoyX: %JoyX%

               ;ToolTip, pJoyX <= 45.0 && JoyX_has_Reset_PPSSPP == 0 && PPSSPP_Speed_Toggle != 1
               ;Sleep, 1200


               PPSSPP_Speed_Toggle_Joy := 1


               ;Tooltip, p1_ <= 45.0 && JoyX_has_Reset_PPSSPP == 0`nStart Speedup -  PPSSPP_Speed_Toggle_Joy: %PPSSPP_Speed_Toggle_Joy%`nJoyX_has_Reset_PPSSPP: %JoyX_has_Reset_PPSSPP% 
               ;Sleep, 1500




               ; Send {Up down} - Send Up arrow keystrokes as long as PPSSPP_Speed_Toggle_Joy == 1
   
               While (PPSSPP_Speed_Toggle_Joy == 1)
               {
   
                  If WinActive("ahk_class PPSSPPWnd")
                  {
                     ;ToolTip, pJoyX_has_Reset_PPSSPP: %JoyX_has_Reset_PPSSPP% `r`nJoyX: %JoyX%
                     ;Sleep, 2300
   
                     Send {Up down}
                     Sleep, 120   ; or Sleep, 210
   
   
                     GetKeyState, JoyX, 1JoyX
   
   
         
                     ; use Left Joystick move left to disable the speed increase
         
                     if (JoyX>=49 and Joyx <=50.5 &&  JoyX_has_Reset_PPSSPP == 1)
                     {
                        JoyX_has_Reset_PPSSPP := 2
   
                        ;Tooltip, p2_ >=49 && <=50.5: PPSSPP_Speed_Toggle_Joy: %PPSSPP_Speed_Toggle_Joy%`nJoyX_has_Reset_PPSSPP: %JoyX_has_Reset_PPSSPP%
                        ;Sleep, 1500
                     }
   
   
   
                     ; use Left Joystick move left to disable the speed increase - The Left Joystick was reset to the center position after being moved left to start the speed increase and now is moved again to the left to stop the speed increase
                     if (JoyX <= 45.0 && JoyX_has_Reset_PPSSPP == 2)
                     {
   
                        JoyX_has_Reset_PPSSPP := 3
   
                        ;Tooltip, p3_ <45: - PPSSPP_Speed_Toggle_Joy: %PPSSPP_Speed_Toggle_Joy%`nJoyX_has_Reset_PPSSPP: %JoyX_has_Reset_PPSSPP%
                        ;Sleep, 1500
                     }
   
   
   
                             
                     if (JoyX>=49 and Joyx <=50.5 && JoyX_has_Reset_PPSSPP == 3)
                     {
                                 
                        Send {Up up}
                        Sleep 50
   
                        PPSSPP_Speed_Toggle_Joy := 0
                        JoyX_has_Reset_PPSSPP := 0
   
                        ;Tooltip, p0_ Full reset: - PPSSPP_Speed_Toggle_Joy: %PPSSPP_Speed_Toggle_Joy%`nJoyX_has_Reset_PPSSPP: %JoyX_has_Reset_PPSSPP%
                        ;Sleep, 1500
                     }
   
   
   
   
   
                     ;Send {Up up} toggles the speed increase
   
                     ; use the Down arrow key for to change the game to normal speed and disable the speed increase
                     
                     if ( GetKeyState("Down", "p") == True)
                     {
                        PPSSPP_Speed_Toggle := 0
                        Send {Up up}
                        JoyX_has_Reset_PPSSPP := 3   ; needed for the functionality - use Left Joystick move left to disable the speed increase
                     }
   
   
   
                     ; if the left mouse is pressed (for example to click the PPSSPP menu), disable the speed increase
                     ; it doesn't work very well wen clicking on the menu items instead of the main window
                     LButton_State_Joy := GetKeyState("LButton", "p")
                     RButton_State_Joy := GetKeyState("RButton", "p")
             
                     if ( LButton_State_Joy == True or RButton_State_Joy == True)
                     {
                        PPSSPP_Speed_Toggle := 0
                        Send {Up up}
                        JoyX_has_Reset_PPSSPP := 3   ; needed for the functionality - use Left Joystick move left to disable the speed increase
                     }
   
   
   
                     ; You may also want to use the v key in the emulator controller mapping settings, for the x (cross) button on the controller for selecting - disable speed increase if v is pressed
   
                    ; use the f key  - disable speed increase if v is pressed
                    if ( GetKeyState("f", "p") == True)
                    {
                        PPSSPP_Speed_Toggle := 0
                        Send {Up up}
                        JoyX_has_Reset_PPSSPP := 3   ; needed for the functionality - use Left Joystick move left to disable the speed increase
                    }
   
                    ; use the b key for the O (circle) button on the controller for selecting - disable speed increase if b is pressed
   
                    if ( GetKeyState("b", "p") == True)
                    {
                        PPSSPP_Speed_Toggle := 0
                        Send {Up up}
                        JoyX_has_Reset_PPSSPP := 3   ; needed for the functionality - use Left Joystick move left to disable the speed increase
                    }
   
   
   
                    ; use the Cross (or X) key on the controller to change the game to normal speed and disable the speed increase
   
                    if ( GetKeyState("joy1", "p") == True)
                    {
                        PPSSPP_Speed_Toggle := 0
                        Send {Up up}
                        JoyX_has_Reset_PPSSPP := 3   ; needed for the functionality - use Left Joystick move left to disable the speed increase
                    }
   
   
   
                    ; use the Circle key on the controller to change the game to normal speed and disable the speed increase
   
                    if ( GetKeyState("joy2", "p") == True)
                    {
                        PPSSPP_Speed_Toggle := 0
                        Send {Up up}
                        JoyX_has_Reset_PPSSPP := 3   ; needed for the functionality - use Left Joystick move left to disable the speed increase
                    }
   
   
                    ; use the Square key on the controller to change the game to normal speed and disable the speed increase
   
                    if ( GetKeyState("joy3", "p") == True)
                    {
                        PPSSPP_Speed_Toggle := 0
                        Send {Up up}
                        JoyX_has_Reset_PPSSPP := 3   ; needed for the functionality - use Left Joystick move left to disable the speed increase
                    }
   
   
   
   
   
                    ; use the Triangle key on the controller to change the game to normal speed and disable the speed increase
   
                    if ( GetKeyState("joy4", "p") == True)
                    {
                        PPSSPP_Speed_Toggle := 0
                        Send {Up up}
                        JoyX_has_Reset_PPSSPP := 3   ; needed for the functionality - use Left Joystick move left to disable the speed increase
                    }
   
   
   
   
                     ; use Left Thumbstick move right to disable the speed increase started by moving the Left Thumbstick to the left
   
                     if JoyX >= 55.0
                     {
                        Send {Up up}
                        Sleep 50
   
                        PPSSPP_Speed_Toggle_Joy := 0
                        JoyX_has_Reset_PPSSPP := 0
                     }
   
   
   
   
                  }   ; end for If WinActive("ahk_class PPSSPPWnd")
   
   
   
                  ; stop the automatic key press if the focus is moved  to another application window
                  else
                  {
                     PPSSPP_Speed_Toggle := 0
                     Send {Up up}
                     JoyX_has_Reset_PPSSPP := 0
                     PPSSPP_Speed_Toggle_Joy :=0
                  }
   
   
               } ; end> While (PPSSPP_Speed_Toggle_Joy == 1)


            } ; end> if (JoyX <= 45.0 && JoyX_has_Reset_PPSSPP == 0 && PPSSPP_Speed_Toggle != 1 )
   

         }   ; end> If WinActive("ahk_class PPSSPPWnd")



      } ; for if ("" . JoyX != "")


   return ;for WatchAxis

;} ; for the Loop


Return   ; end> ahk_group Group_game_speed_toggle
}
#IfWinActive   ; end> ahk_group Group_game_speed_toggle





; END -------------------------; Joystick settings for Emulators
;
;
;--------------------------------------------------------------------------------











;; HERE, AFTER THIS LINE, YOU CAN PLACE THE AUTOHOTKEY CODE FOR OTHER SOFTWARE THAT YOU USE:
;; Along with code for other software this is where you can put the code for the software that use the speed toggle
;; The problem was that the code for the game controller needed to be run before this section so it needed to be placed on the top of the script.



; THE FOLLOWING CODE LINES ARE NOT NEEDED FOR THE SPEED TOGGLE, I PUT THIS IN ORDER FOR YOU TO SEE HOW TO USE THE SCRIPT CODE WITH OTHER PROGRAMS

; SECTION FOR GLOBAL KEYS:

; Pause as PrintScreen Button
;Pause::PrintScreen


;;TOGGLE Always on top for any window - Ctrl+Alt+Shift+F11
;^!+F11::  Winset, Alwaysontop, , A
;return













; THE FOLLOWING CODE IS NEEDED FOR THE SPEED TOGGLE - i.e. the code for the emulators: BizHawk (EmuHawk.exe) and PPSSPP (PPSSPPWindows64.exe)


; BizHawk emulator (EmuHawk.exe is the launcher)

#IfWinActive, ahk_exe EmuHawk.exe
{

#MaxThreadsPerHotkey 2

   ; How To Use the Up Arrow on the keyboard to increase the speed for the Emulator BizHawk (for Final Fantasy IX - PS1 version).
   ; #MaxThreadsPerHotkey 2 is vital for the toggle to work, for the same key to be registered when is pressed again



   ; BizHawk_Speed_Toggle := is initialized with 0 in the global variables section 
   ; It is important that BizHawk_Speed_Toggle has the value 0 when it exits the code block for the joystick detection section and buttons
   ; This zero value has to be 0 as the init value for the Up:: button section



   ;Tooltip, BizHawk_Speed_Toggle: %BizHawk_Speed_Toggle%
   ;Sleep 1300


   ; Because we use a variable as a toggle, to control the game speed toggle, we can use different buttons to toggle this variable if we want multiple buttons to be able to toggle the speed increase.
   ; For thumbsticks you have to use separate variables.
   ; Usually the game is setup from its preferences to use the Up arrow key kept held down to activate the fast speed mode, for example the 4x speed mode


Up::


;  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!   VERY IMPORTANT   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - It's important to put Send {Up up} first, 
;  then BizHawk_Speed_Toggle := !BizHawk_Speed_Toggle and then Sleep 110 or (Sleep 50)

   ;Tooltip, BizHawk_Speed_Toggle:  %BizHawk_Speed_Toggle%`nBizHawk_Speed_Toggle_Joy: %BizHawk_Speed_Toggle_Joy%
   ;Sleep 1300

   if (BizHawk_Speed_Toggle_Joy == 1 && JoyX_has_Reset_BizHawk != 1)   ;; prevent part 2: prevent up button effect when joy was moved left first - that is why  I added: && JoyX_has_Reset_BizHawk != 1
   {
      ;Tooltip, if JoyX_has_Reset_BizHawk: %JoyX_has_Reset_BizHawk%`nBizHawk_Speed_Toggle_Joy: %BizHawk_Speed_Toggle_Joy%
      ;Sleep, 900

      BizHawk_Speed_Toggle_Joy := 0
      JoyX_has_Reset_BizHawk := 3
   }

   ; prevent part 2: prevent up button effect when joy was moved left first - that is why  I added: if (BizHawk_Speed_Toggle_Joy == 0)
   else if (BizHawk_Speed_Toggle_Joy == 0)
   {


      ;Tooltip, else JoyX_has_Reset_BizHawk: %JoyX_has_Reset_BizHawk%`nBizHawk_Speed_Toggle_Joy: %BizHawk_Speed_Toggle_Joy%
      ;Sleep, 900


      Send {Up up}
      BizHawk_Speed_Toggle := !BizHawk_Speed_Toggle

      ;Tooltip, BizHawk_Speed_Toggle: %BizHawk_Speed_Toggle%
      ;Sleep 300

      ;Sleep 150   ; or Sleep 110
      Sleep 50


      JoyX_has_Reset_BizHawk := 0


      While BizHawk_Speed_Toggle
      {

         If WinActive("ahk_class WindowsForms10.Window.8.app.0.ffe60_r12_ad1")   ; EmuHawk window is active
         {

            ; Without Sleep the Toggle does not work because it doesn't have time to act, the Up arrow will be pressed continuously
            ; And the toggle cannot interrupt the Up arrow key press



            Send {Up down}
            Sleep 50


            ;Tooltip, Up loop start - BizHawk_Speed_Toggle: %BizHawk_Speed_Toggle%
            ;Sleep 200




            ; use the Down arrow key for to change the game to normal speed and disable the speed increase

            if ( GetKeyState("Down", "p") == True)
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }


            ; You may also want to use the v key for the x (cross) button on the controller for selecting - disable speed increase if v is pressed

            ; use the f key  - disable speed increase if v is pressed
            if ( GetKeyState("f", "p") == True)
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }

            ; use the b key for the O (circle) button on the controller for selecting - disable speed increase if b is pressed

            if ( GetKeyState("b", "p") == True)
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }


            ; use the v key for the cross (or X) button on the controller - disable speed increase if v is pressed

            if ( GetKeyState("v", "p") == True)+
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }


            ; use the r key for the square button on the controller - disable speed increase if r is pressed

            if ( GetKeyState("r", "p") == True)
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }



            ; use the t key for the triangle button on the controller - disable speed increase if t is pressed

            if ( GetKeyState("t", "p") == True)
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }


            ; the Shift key is used in combination with other key to save the game - disable speed increase if the Shift key is pressed

            if ( GetKeyState("shift", "p") == True)
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }


            ; use the Cross (or X) key on the controller to change the game to normal speed and disable the speed increase

            GetKeyState, joy1_cross, 1joy1       ;1joy1 means Joystick 1 (the first 1 or 1joy1) and button joy1 which is the Cross (or X) button
            if joy1_cross = D    ; the 1joy1 button is down
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }



            ; use the Circle key on the controller to change the game to normal speed and disable the speed increase

            GetKeyState, joy1_circle, 1joy2       ;1joy2 means Joystick 1 (the first 1 or 1joy2) and button joy2 which is the Circle button
            if joy1_circle = D    ; the 1joy2 button is down
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }



            ; use the Square key on the controller to change the game to normal speed and disable the speed increase

            GetKeyState, joy1_square, 1joy3       ;1joy3 means Joystick 1 (the first 1 or 1joy3) and button joy3 which is the Square button
            if joy1_square = D    ; the 1joy3 button is down
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }


            ; use the Triangle key on the controller to change the game to normal speed and disable the speed increase

            GetKeyState, joy1_triangle, 1joy4       ;1joy4 means Joystick 1 (the first 1 or 1joy4) and button joy4 which is the Triangle button
            if joy1_triangle = D    ; the 1joy4 button is down
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }


            ;Tooltip, Up loop - bottom - BizHawk_Speed_Toggle: %BizHawk_Speed_Toggle%
            ;Sleep 300

            ; L1 and R1 buttons will be used to toggle the speed increase, just like the Up arrow button, in their own sections.
            ; so is not required to implement code here for these buttons.



;            ; Because the Left Thumbstick Moved Left is implemented as a speed toggle,
;            ; if you try to implement code here, in the section for the Up arrow button, for Left Movement of the Left Thumbstick,
;            ; it will not be run, instead the code run will be the one on the Joystick section for the Left Movement of the Left Joystick.
;            ;
;            ; Contrary to that, if you try to implement code here for the movement to the Right of the Left Thumbstick, this code
;            ; will be run because the movement to the Right of the Left Thumbstick doesn't trigger a speed toggle, it just stops the speed increase
;
;

;            ; BEGIN - NOT USED ANYMORE WHEN THE LEFT CONTROLLER THUMBSTICK IS MOVED TO THE LEFT - THIS IS IMPLEMENTED IN THE JOYSTICK SECTION,
;            ; You can use this section if you don't have other code 
;            ; If you don't use a Joystick section at all ;for example to toggle the speed increase ; you can use the following code for the Left Joystick move left to disable the speed increase that was started by the Up arrow button. 
;            ; But you cannot start the speed increase using the Left Joystick, for that you need the Joystick section at the top of the script file
;
;            ;GetKeyState, JoyX, 1JoyX   ; it is used a few lines up
;            ;ToolTip, JoyX: %JoyX%
;            if ("" . JoyX != "" && JoyX <= 45.0  && JoyX_has_Reset_BizHawk == 0)
;            {
;               ;Tooltip, JoyX<=45.0  && JoyX_has_Reset_BizHawk`nJoyX_has_Reset_BizHawk: %JoyX_has_Reset_BizHawk%
;               ;Sleep 2900
;               JoyX_has_Reset_BizHawk := 1
;               ;Tooltip, JoyX<=45.0  && JoyX_has_Reset_BizHawk`nBizHawk_Speed_Toggle: %BizHawk_Speed_Toggle%`nJoyX_has_Reset_BizHawk: %JoyX_has_Reset_BizHawk%`nBizHawk_Speed_Toggle_Joy: %BizHawk_Speed_Toggle_Joy%
;               ;Sleep 2900
;            }
;            if (JoyX>=49 and Joyx <=50.5 &&  JoyX_has_Reset_BizHawk == 1)
;            {
;               Send {Up up}
;               JoyX_has_Reset_BizHawk := 0
;               BizHawk_Speed_Toggle := 0
;               ;Tooltip, JoyX>=49 and Joyx<=50.5`nJoy BizHawk_Speed_Toggle:`nBizHawk_Speed_Toggle: %BizHawk_Speed_Toggle%`nJoyX_has_Reset_BizHawk: %JoyX_has_Reset_BizHawk%`nBizHawk_Speed_Toggle_Joy: %BizHawk_Speed_Toggle_Joy%
;               ;Sleep 2900
;            }



            ; use Left Thumbstick move right to disable the speed increase started by the Up arrow button
            if JoyX >= 55.0
            {
               Send {Up up}
               Sleep 50
   
               JoyX_has_Reset_BizHawk := 0
               BizHawk_Speed_Toggle := 0
            }



            ;LButton_state := GetKeyState("LButton")
            ;RButton_state := GetKeyState("RButton")
            ;ToolTip, window_LButton: %LButton_state% `r`nwindow_RButton: %RButton_state% 


            ; if the left mouse is pressed (for example to click the PPSSPP menu), disable the speed increase
            ; it doesn't work very well wen clicking on the menu items instead of the main window
            LButton_State := GetKeyState("LButton", "p")
            RButton_State := GetKeyState("RButton", "p")
        
            if ( LButton_State == True or RButton_State == True)
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }
   
   
         } ; end for If WinActive("ahk_class WindowsForms10.Window.8.app.0.ffe60_r12_ad1")
   
   
   
         ; stop the automatic key press if the focus is moved  to another application window
         else
         {
            Send {Up up}
            BizHawk_Speed_Toggle := 0
         }


      } ; end >  While BizHawk_Speed_Toggle

   }   ; end > else if (BizHawk_Speed_Toggle_Joy == 0)

return   ;return for Up button> Up::




   ; use L1 button to toggle the speed increase

joy5::

;  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!   VERY IMPORTANT   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - It's important to put Send {Up up} first, 
;  then BizHawk_Speed_Toggle := !BizHawk_Speed_Toggle and then Sleep 110 or (Sleep 50)

   ;Tooltip, BizHawk_Speed_Toggle:  %BizHawk_Speed_Toggle%`nBizHawk_Speed_Toggle_Joy: %BizHawk_Speed_Toggle_Joy%
   ;Sleep 1300

   if (BizHawk_Speed_Toggle_Joy == 1 && JoyX_has_Reset_BizHawk != 1)   ;; prevent part 2: prevent up button effect when joy was moved left first - that is why  I added: && JoyX_has_Reset_BizHawk != 1
   {
      ;Tooltip, if JoyX_has_Reset_BizHawk: %JoyX_has_Reset_BizHawk%`nBizHawk_Speed_Toggle_Joy: %BizHawk_Speed_Toggle_Joy%
      ;Sleep, 900

      BizHawk_Speed_Toggle_Joy := 0
      JoyX_has_Reset_BizHawk := 3
   }

   ; prevent part 2: prevent up button effect when joy was moved left first - that is why  I added: if (BizHawk_Speed_Toggle_Joy == 0)
   else if (BizHawk_Speed_Toggle_Joy == 0)
   {


      ;Tooltip, else JoyX_has_Reset_BizHawk: %JoyX_has_Reset_BizHawk%`nBizHawk_Speed_Toggle_Joy: %BizHawk_Speed_Toggle_Joy%
      ;Sleep, 900


      Send {Up up}
      BizHawk_Speed_Toggle := !BizHawk_Speed_Toggle

      ;Tooltip, BizHawk_Speed_Toggle: %BizHawk_Speed_Toggle%
      ;Sleep 300

      ;Sleep 150   ; or Sleep 110
      Sleep 50


      JoyX_has_Reset_BizHawk := 0


      While BizHawk_Speed_Toggle
      {

         If WinActive("ahk_class WindowsForms10.Window.8.app.0.ffe60_r12_ad1")   ; EmuHawk window is active
         {

            ; Without Sleep the Toggle does not work because it doesn't have time to act, the Up arrow will be pressed continuously
            ; And the toggle cannot interrupt the Up arrow key press



            Send {Up down}
            Sleep 50


            ;Tooltip, Up loop start - BizHawk_Speed_Toggle: %BizHawk_Speed_Toggle%
            ;Sleep 200




            ; use the Down arrow key for to change the game to normal speed and disable the speed increase

            if ( GetKeyState("Down", "p") == True)
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }


            ; You may also want to use the v key for the x (cross) button on the controller for selecting - disable speed increase if v is pressed

            ; use the f key  - disable speed increase if v is pressed
            if ( GetKeyState("f", "p") == True)
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }

            ; use the b key for the O (circle) button on the controller for selecting - disable speed increase if b is pressed

            if ( GetKeyState("b", "p") == True)
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }


            ; use the v key for the cross (or X) button on the controller - disable speed increase if v is pressed

            if ( GetKeyState("v", "p") == True)+
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }


            ; use the r key for the square button on the controller - disable speed increase if r is pressed

            if ( GetKeyState("r", "p") == True)
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }



            ; use the t key for the triangle button on the controller - disable speed increase if t is pressed

            if ( GetKeyState("t", "p") == True)
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }




            ; the Shift key is used in combination with other key to save the game - disable speed increase if the Shift key is pressed

            if ( GetKeyState("shift", "p") == True)
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }




            ; use the Cross (or X) key on the controller to change the game to normal speed and disable the speed increase

            GetKeyState, joy1_cross, 1joy1       ;1joy1 means Joystick 1 (the first 1 or 1joy1) and button joy1 which is the Cross (or X) button
            if joy1_cross = D    ; the 1joy1 button is down
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }



            ; use the Circle key on the controller to change the game to normal speed and disable the speed increase

            GetKeyState, joy1_circle, 1joy2       ;1joy2 means Joystick 1 (the first 1 or 1joy2) and button joy2 which is the Circle button
            if joy1_circle = D    ; the 1joy2 button is down
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }



            ; use the Square key on the controller to change the game to normal speed and disable the speed increase

            GetKeyState, joy1_square, 1joy3       ;1joy3 means Joystick 1 (the first 1 or 1joy3) and button joy3 which is the Square button
            if joy1_square = D    ; the 1joy3 button is down
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }


            ; use the Triangle key on the controller to change the game to normal speed and disable the speed increase

            GetKeyState, joy1_triangle, 1joy4       ;1joy4 means Joystick 1 (the first 1 or 1joy4) and button joy4 which is the Triangle button
            if joy1_triangle = D    ; the 1joy4 button is down
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }


            ;Tooltip, Up loop - bottom - BizHawk_Speed_Toggle: %BizHawk_Speed_Toggle%
            ;Sleep 300



            ; use Left Thumbstick move right to disable the speed increase started by the Up arrow button
            if JoyX >= 55.0
            {
               Send {Up up}
               Sleep 50
   
               JoyX_has_Reset_BizHawk := 0
               BizHawk_Speed_Toggle := 0
            }



            ;LButton_state := GetKeyState("LButton")
            ;RButton_state := GetKeyState("RButton")
            ;ToolTip, window_LButton: %LButton_state% `r`nwindow_RButton: %RButton_state% 



            ; if the left mouse is pressed (for example to click the PPSSPP menu), disable the speed increase
            ; it doesn't work very well wen clicking on the menu items instead of the main window
            LButton_State := GetKeyState("LButton", "p")
            RButton_State := GetKeyState("RButton", "p")
        
            if ( LButton_State == True or RButton_State == True)
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }


         } ; end for If WinActive("ahk_class WindowsForms10.Window.8.app.0.ffe60_r12_ad1")



         ; stop the automatic key press if the focus is moved  to another application window
         else
         {
            Send {Up up}
            BizHawk_Speed_Toggle := 0
         }


      } ; end >  While BizHawk_Speed_Toggle


   }   ; end > else if (BizHawk_Speed_Toggle_Joy == 0)

return   ;return for L1 button> joy5::






   ; use R1 button to toggle the speed increase
   ; to accelerate through the game dialogues, etc. , leave out the Cross (or X) button from the list of buttons that can stop the R1 button speed increase

joy6::

;  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!   VERY IMPORTANT   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - It's important to put Send {Up up} first, 
;  then BizHawk_Speed_Toggle := !BizHawk_Speed_Toggle and then Sleep 110 or (Sleep 50)

   ;Tooltip, BizHawk_Speed_Toggle:  %BizHawk_Speed_Toggle%`nBizHawk_Speed_Toggle_Joy: %BizHawk_Speed_Toggle_Joy%
   ;Sleep 1300

   if (BizHawk_Speed_Toggle_Joy == 1 && JoyX_has_Reset_BizHawk != 1)   ;; prevent part 2: prevent up button effect when joy was moved left first - that is why  I added: && JoyX_has_Reset_BizHawk != 1
   {
      ;Tooltip, if JoyX_has_Reset_BizHawk: %JoyX_has_Reset_BizHawk%`nBizHawk_Speed_Toggle_Joy: %BizHawk_Speed_Toggle_Joy%
      ;Sleep, 900

      BizHawk_Speed_Toggle_Joy := 0
      JoyX_has_Reset_BizHawk := 3
   }

   ; prevent part 2: prevent up button effect when joy was moved left first - that is why  I added: if (BizHawk_Speed_Toggle_Joy == 0)
   else if (BizHawk_Speed_Toggle_Joy == 0)
   {


      ;Tooltip, else JoyX_has_Reset_BizHawk: %JoyX_has_Reset_BizHawk%`nBizHawk_Speed_Toggle_Joy: %BizHawk_Speed_Toggle_Joy%
      ;Sleep, 900


      Send {Up up}
      BizHawk_Speed_Toggle := !BizHawk_Speed_Toggle

      ;Tooltip, BizHawk_Speed_Toggle: %BizHawk_Speed_Toggle%
      ;Sleep 300

      ;Sleep 150   ; or Sleep 110
      Sleep 50


      JoyX_has_Reset_BizHawk := 0


      While BizHawk_Speed_Toggle
      {

         If WinActive("ahk_class WindowsForms10.Window.8.app.0.ffe60_r12_ad1")   ; EmuHawk window is active
         {

            ; Without Sleep the Toggle does not work because it doesn't have time to act, the Up arrow will be pressed continuously
            ; And the toggle cannot interrupt the Up arrow key press



            Send {Up down}
            Sleep 50


            ;Tooltip, Up loop start - BizHawk_Speed_Toggle: %BizHawk_Speed_Toggle%
            ;Sleep 200




            ; use the Down arrow key for to change the game to normal speed and disable the speed increase

            if ( GetKeyState("Down", "p") == True)
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }


            ; You may also want to use the v key for the x (cross) button on the controller for selecting - disable speed increase if v is pressed

            ; use the f key  - disable speed increase if v is pressed
            if ( GetKeyState("f", "p") == True)
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }

            ; use the b key for the O (circle) button on the controller for selecting - disable speed increase if b is pressed

            if ( GetKeyState("b", "p") == True)
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }


            ; use the v key for the cross (or X) button on the controller - disable speed increase if v is pressed

            if ( GetKeyState("v", "p") == True)+
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }


            ; use the r key for the square button on the controller - disable speed increase if r is pressed

            if ( GetKeyState("r", "p") == True)
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }



            ; use the t key for the triangle button on the controller - disable speed increase if t is pressed

            if ( GetKeyState("t", "p") == True)
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }




            ; the Shift key is used in combination with other key to save the game - disable speed increase if the Shift key is pressed

            if ( GetKeyState("shift", "p") == True)
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }




;            ; use the Cross (or X) key on the controller to change the game to normal speed and disable the speed increase
;
;            GetKeyState, joy1_cross, 1joy1       ;1joy1 means Joystick 1 (the first 1 or 1joy1) and button joy1 which is the Cross (or X) button
;            if joy1_cross = D    ; the 1joy1 button is down
;            {
;               BizHawk_Speed_Toggle := 0
;               Send {Up up}
;            }



            ; use the Circle key on the controller to change the game to normal speed and disable the speed increase

            GetKeyState, joy1_circle, 1joy2       ;1joy2 means Joystick 1 (the first 1 or 1joy2) and button joy2 which is the Circle button
            if joy1_circle = D    ; the 1joy2 button is down
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }



            ; use the Square key on the controller to change the game to normal speed and disable the speed increase

            GetKeyState, joy1_square, 1joy3       ;1joy3 means Joystick 1 (the first 1 or 1joy3) and button joy3 which is the Square button
            if joy1_square = D    ; the 1joy3 button is down
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }


            ; use the Triangle key on the controller to change the game to normal speed and disable the speed increase

            GetKeyState, joy1_triangle, 1joy4       ;1joy4 means Joystick 1 (the first 1 or 1joy4) and button joy4 which is the Triangle button
            if joy1_triangle = D    ; the 1joy4 button is down
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }


            ;Tooltip, Up loop - bottom - BizHawk_Speed_Toggle: %BizHawk_Speed_Toggle%
            ;Sleep 300



            ; use Left Thumbstick move right to disable the speed increase started by the Up arrow button
            if JoyX >= 55.0
            {
               Send {Up up}
               Sleep 50
   
               JoyX_has_Reset_BizHawk := 0
               BizHawk_Speed_Toggle := 0
            }



            ;LButton_state := GetKeyState("LButton")
            ;RButton_state := GetKeyState("RButton")
            ;ToolTip, window_LButton: %LButton_state% `r`nwindow_RButton: %RButton_state% 



            ; if the left mouse is pressed (for example to click the PPSSPP menu), disable the speed increase
            ; it doesn't work very well wen clicking on the menu items instead of the main window
            LButton_State := GetKeyState("LButton", "p")
            RButton_State := GetKeyState("RButton", "p")

            if ( LButton_State == True or RButton_State == True)
            {
               BizHawk_Speed_Toggle := 0
               Send {Up up}
            }


         } ; end for If WinActive("ahk_class WindowsForms10.Window.8.app.0.ffe60_r12_ad1")



         ; stop the automatic key press if the focus is moved  to another application window
         else
         {
            BizHawk_Speed_Toggle := 0
         }


      } ; end >  While BizHawk_Speed_Toggle


   }   ; end > else if (BizHawk_Speed_Toggle_Joy == 0)

return   ;return for R1 button> joy6::




Return   ;Return for #IfWinActive, ahk_exe EmuHawk.exe
}








#IfWinActive, ahk_exe PPSSPPWindows64.exe
{

#MaxThreadsPerHotkey 2

   ; How To Use the Up Arrow on the keyboard to increase the speed for the PSP (Playstation Portable) Emulator PPSSPP (for Final Fantasy Tactics - PSP version).
   ; #MaxThreadsPerHotkey 2 is vital for the toggle to work, for the same key to be registered when is pressed again



   ; PPSSPP_Speed_Toggle := is initialized with 0 in the global variables section 
   ; It is important that PPSSPP_Speed_Toggle has the value 0 when it exits the code block for the joystick detection section and buttons
   ; This zero value has to be 0 as the init value for the Up:: button section



   ;Tooltip, PPSSPP_Speed_Toggle: %PPSSPP_Speed_Toggle%
   ;Sleep 1300


   ; Because we use a variable as a toggle, to control the game speed toggle, we can use different buttons to toggle this variable if we want multiple buttons to be able to toggle the speed increase.
   ; For thumbsticks you have to use separate variables.
   ; Usually the game is setup from its preferences to use the Up arrow key kept held down to activate the fast speed mode, for example the 4x speed mode


Up::


;  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!   VERY IMPORTANT   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - It's important to put Send {Up up} first, 
;  then PPSSPP_Speed_Toggle := !PPSSPP_Speed_Toggle and then Sleep 110 or (Sleep 50)

   ;Tooltip, PPSSPP_Speed_Toggle:  %PPSSPP_Speed_Toggle%`nPPSSPP_Speed_Toggle_Joy: %PPSSPP_Speed_Toggle_Joy%
   ;Sleep 1300

   if (PPSSPP_Speed_Toggle_Joy == 1 && JoyX_has_Reset_PPSSPP != 1)   ;; prevent part 2: prevent up button effect when joy was moved left first - that is why  I added: && JoyX_has_Reset_PPSSPP != 1
   {
      ;Tooltip, if JoyX_has_Reset_PPSSPP: %JoyX_has_Reset_PPSSPP%`nPPSSPP_Speed_Toggle_Joy: %PPSSPP_Speed_Toggle_Joy%
      ;Sleep, 900

      PPSSPP_Speed_Toggle_Joy := 0
      JoyX_has_Reset_PPSSPP := 3
   }

   ; prevent part 2: prevent up button effect when joy was moved left first - that is why  I added: if (PPSSPP_Speed_Toggle_Joy == 0)
   else if (PPSSPP_Speed_Toggle_Joy == 0)
   {


      ;Tooltip, else JoyX_has_Reset_PPSSPP: %JoyX_has_Reset_PPSSPP%`nPPSSPP_Speed_Toggle_Joy: %PPSSPP_Speed_Toggle_Joy%
      ;Sleep, 900


      Send {Up up}
      PPSSPP_Speed_Toggle := !PPSSPP_Speed_Toggle

      ;Tooltip, PPSSPP_Speed_Toggle: %PPSSPP_Speed_Toggle%
      ;Sleep 300

      ;Sleep 150   ; or Sleep 110
      Sleep 50


      JoyX_has_Reset_PPSSPP := 0


      While PPSSPP_Speed_Toggle
      {

         If WinActive("ahk_class PPSSPPWnd")   ; PPSSPP window is active
         {

            ; Without Sleep the Toggle does not work because it doesn't have time to act, the Up arrow will be pressed continuously
            ; And the toggle cannot interrupt the Up arrow key press



            Send {Up down}
            Sleep 50


            ;Tooltip, Up loop start - PPSSPP_Speed_Toggle: %PPSSPP_Speed_Toggle%
            ;Sleep 200




            ; use the Down arrow key for to change the game to normal speed and disable the speed increase

            if ( GetKeyState("Down", "p") == True)
            {
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }


            ; You may also want to use the v key for the x (cross) button on the controller for selecting - disable speed increase if v is pressed

            ; use the f key  - disable speed increase if v is pressed
            if ( GetKeyState("f", "p") == True)
            {
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }

            ; use the b key for the O (circle) button on the controller for selecting - disable speed increase if b is pressed

            if ( GetKeyState("b", "p") == True)
            {
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }


            ; use the v key for the cross (or X) button on the controller - disable speed increase if v is pressed

            if ( GetKeyState("v", "p") == True)+
            {
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }


            ; use the r key for the square button on the controller - disable speed increase if r is pressed

            if ( GetKeyState("r", "p") == True)
            {
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }



            ; use the t key for the triangle button on the controller - disable speed increase if t is pressed

            if ( GetKeyState("t", "p") == True)
            {
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }



            ; use the Cross (or X) key on the controller to change the game to normal speed and disable the speed increase

            GetKeyState, joy1_cross, 1joy1       ;1joy1 means Joystick 1 (the first 1 or 1joy1) and button joy1 which is the Cross (or X) button
            if joy1_cross = D    ; the 1joy1 button is down
            {
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }



            ; use the Circle key on the controller to change the game to normal speed and disable the speed increase

            GetKeyState, joy1_circle, 1joy2       ;1joy2 means Joystick 1 (the first 1 or 1joy2) and button joy2 which is the Circle button
            if joy1_circle = D    ; the 1joy2 button is down
            {
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }



            ; use the Square key on the controller to change the game to normal speed and disable the speed increase

            GetKeyState, joy1_square, 1joy3       ;1joy3 means Joystick 1 (the first 1 or 1joy3) and button joy3 which is the Square button
            if joy1_square = D    ; the 1joy3 button is down
            {
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }


            ; use the Triangle key on the controller to change the game to normal speed and disable the speed increase

            GetKeyState, joy1_triangle, 1joy4       ;1joy4 means Joystick 1 (the first 1 or 1joy4) and button joy4 which is the Triangle button
            if joy1_triangle = D    ; the 1joy4 button is down
            {
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }


            ;Tooltip, Up loop - bottom - PPSSPP_Speed_Toggle: %PPSSPP_Speed_Toggle%
            ;Sleep 300

            ; L1 and R1 buttons will be used to toggle the speed increase, just like the Up arrow button, in their own sections.
            ; so is not required to implement code here for these buttons.



            ; use Left Thumbstick move right to disable the speed increase started by the Up arrow button
            if JoyX >= 55.0
            {
               Send {Up up}
               Sleep 50
   
               JoyX_has_Reset_PPSSPP := 0
               PPSSPP_Speed_Toggle := 0
            }



            ;LButton_state := GetKeyState("LButton")
            ;RButton_state := GetKeyState("RButton")
            ;ToolTip, window_LButton: %LButton_state% `r`nwindow_RButton: %RButton_state% 


            ; if the left mouse is pressed (for example to click the PPSSPP menu), disable the speed increase
            ; it doesn't work very well wen clicking on the menu items instead of the main window
            LButton_State := GetKeyState("LButton", "p")
            RButton_State := GetKeyState("RButton", "p")
        
            if ( LButton_State == True or RButton_State == True)
            {
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }
   
   
         } ; end for If WinActive("ahk_class PPSSPPWnd")
   
   
   
         ; stop the automatic key press if the focus is moved  to another application window
         else
         {
            PPSSPP_Speed_Toggle := 0
         }


      } ; end >  While PPSSPP_Speed_Toggle

   }   ; end > else if (PPSSPP_Speed_Toggle_Joy == 0)

return   ;return for Up button> Up::




   ; use L1 button to toggle the speed increase

joy5::

;  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!   VERY IMPORTANT   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - It's important to put Send {Up up} first, 
;  then PPSSPP_Speed_Toggle := !PPSSPP_Speed_Toggle and then Sleep 110 or (Sleep 50)

   ;Tooltip, PPSSPP_Speed_Toggle:  %PPSSPP_Speed_Toggle%`nPPSSPP_Speed_Toggle_Joy: %PPSSPP_Speed_Toggle_Joy%
   ;Sleep 1300

   if (PPSSPP_Speed_Toggle_Joy == 1 && JoyX_has_Reset_PPSSPP != 1)   ;; prevent part 2: prevent up button effect when joy was moved left first - that is why  I added: && JoyX_has_Reset_PPSSPP != 1
   {
      ;Tooltip, if JoyX_has_Reset_PPSSPP: %JoyX_has_Reset_PPSSPP%`nPPSSPP_Speed_Toggle_Joy: %PPSSPP_Speed_Toggle_Joy%
      ;Sleep, 900

      PPSSPP_Speed_Toggle_Joy := 0
      JoyX_has_Reset_PPSSPP := 3
   }

   ; prevent part 2: prevent up button effect when joy was moved left first - that is why  I added: if (PPSSPP_Speed_Toggle_Joy == 0)
   else if (PPSSPP_Speed_Toggle_Joy == 0)
   {


      ;Tooltip, else JoyX_has_Reset_PPSSPP: %JoyX_has_Reset_PPSSPP%`nPPSSPP_Speed_Toggle_Joy: %PPSSPP_Speed_Toggle_Joy%
      ;Sleep, 900


      Send {Up up}
      PPSSPP_Speed_Toggle := !PPSSPP_Speed_Toggle

      ;Tooltip, PPSSPP_Speed_Toggle: %PPSSPP_Speed_Toggle%
      ;Sleep 300

      ;Sleep 150   ; or Sleep 110
      Sleep 50


      JoyX_has_Reset_PPSSPP := 0


      While PPSSPP_Speed_Toggle
      {

         If WinActive("ahk_class PPSSPPWnd")   ; PPSSPP window is active
         {

            ; Without Sleep the Toggle does not work because it doesn't have time to act, the Up arrow will be pressed continuously
            ; And the toggle cannot interrupt the Up arrow key press



            Send {Up down}
            Sleep 50


            ;Tooltip, Up loop start - PPSSPP_Speed_Toggle: %PPSSPP_Speed_Toggle%
            ;Sleep 200




            ; use the Down arrow key for to change the game to normal speed and disable the speed increase

            if ( GetKeyState("Down", "p") == True)
            {
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }


            ; You may also want to use the v key for the x (cross) button on the controller for selecting - disable speed increase if v is pressed

            ; use the f key  - disable speed increase if v is pressed
            if ( GetKeyState("f", "p") == True)
            {
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }

            ; use the b key for the O (circle) button on the controller for selecting - disable speed increase if b is pressed

            if ( GetKeyState("b", "p") == True)
            {
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }


            ; use the v key for the cross (or X) button on the controller - disable speed increase if v is pressed

            if ( GetKeyState("v", "p") == True)+
            {
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }


            ; use the r key for the square button on the controller - disable speed increase if r is pressed

            if ( GetKeyState("r", "p") == True)
            {
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }



            ; use the t key for the triangle button on the controller - disable speed increase if t is pressed

            if ( GetKeyState("t", "p") == True)
            {
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }



            ; use the Cross (or X) key on the controller to change the game to normal speed and disable the speed increase

            GetKeyState, joy1_cross, 1joy1       ;1joy1 means Joystick 1 (the first 1 or 1joy1) and button joy1 which is the Cross (or X) button
            if joy1_cross = D    ; the 1joy1 button is down
            {
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }



            ; use the Circle key on the controller to change the game to normal speed and disable the speed increase

            GetKeyState, joy1_circle, 1joy2       ;1joy2 means Joystick 1 (the first 1 or 1joy2) and button joy2 which is the Circle button
            if joy1_circle = D    ; the 1joy2 button is down
            {
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }



            ; use the Square key on the controller to change the game to normal speed and disable the speed increase

            GetKeyState, joy1_square, 1joy3       ;1joy3 means Joystick 1 (the first 1 or 1joy3) and button joy3 which is the Square button
            if joy1_square = D    ; the 1joy3 button is down
            {
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }


            ; use the Triangle key on the controller to change the game to normal speed and disable the speed increase

            GetKeyState, joy1_triangle, 1joy4       ;1joy4 means Joystick 1 (the first 1 or 1joy4) and button joy4 which is the Triangle button
            if joy1_triangle = D    ; the 1joy4 button is down
            {
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }


            ;Tooltip, Up loop - bottom - PPSSPP_Speed_Toggle: %PPSSPP_Speed_Toggle%
            ;Sleep 300



            ; use Left Thumbstick move right to disable the speed increase started by the Up arrow button
            if JoyX >= 55.0
            {
               Send {Up up}
               Sleep 50
   
               JoyX_has_Reset_PPSSPP := 0
               PPSSPP_Speed_Toggle := 0
            }



            ;LButton_state := GetKeyState("LButton")
            ;RButton_state := GetKeyState("RButton")
            ;ToolTip, window_LButton: %LButton_state% `r`nwindow_RButton: %RButton_state% 



            ; if the left mouse is pressed (for example to click the PPSSPP menu), disable the speed increase
            ; it doesn't work very well wen clicking on the menu items instead of the main window
            LButton_State := GetKeyState("LButton", "p")
            RButton_State := GetKeyState("RButton", "p")
        
            if ( LButton_State == True or RButton_State == True)
            {
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }


         } ; end for If WinActive("ahk_class PPSSPPWnd")



         ; stop the automatic key press if the focus is moved  to another application window
         else
         {
            PPSSPP_Speed_Toggle := 0
         }


      } ; end >  While PPSSPP_Speed_Toggle


   }   ; end > else if (PPSSPP_Speed_Toggle_Joy == 0)

return   ;return for L1 button> joy5::






   ; use R1 button to toggle the speed increase
   ; to accelerate through the game dialogues, etc. , leave out the Cross (or X) button from the list of buttons that can stop the R1 button speed increase

joy6::

;  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!   VERY IMPORTANT   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - It's important to put Send {Up up} first, 
;  then PPSSPP_Speed_Toggle := !PPSSPP_Speed_Toggle and then Sleep 110 or (Sleep 50)

   ;Tooltip, PPSSPP_Speed_Toggle:  %PPSSPP_Speed_Toggle%`nPPSSPP_Speed_Toggle_Joy: %PPSSPP_Speed_Toggle_Joy%
   ;Sleep 1300

   if (PPSSPP_Speed_Toggle_Joy == 1 && JoyX_has_Reset_PPSSPP != 1)   ;; prevent part 2: prevent up button effect when joy was moved left first - that is why  I added: && JoyX_has_Reset_PPSSPP != 1
   {
      ;Tooltip, if JoyX_has_Reset_PPSSPP: %JoyX_has_Reset_PPSSPP%`nPPSSPP_Speed_Toggle_Joy: %PPSSPP_Speed_Toggle_Joy%
      ;Sleep, 900

      PPSSPP_Speed_Toggle_Joy := 0
      JoyX_has_Reset_PPSSPP := 3
   }

   ; prevent part 2: prevent up button effect when joy was moved left first - that is why  I added: if (PPSSPP_Speed_Toggle_Joy == 0)
   else if (PPSSPP_Speed_Toggle_Joy == 0)
   {


      ;Tooltip, else JoyX_has_Reset_PPSSPP: %JoyX_has_Reset_PPSSPP%`nPPSSPP_Speed_Toggle_Joy: %PPSSPP_Speed_Toggle_Joy%
      ;Sleep, 900


      Send {Up up}
      PPSSPP_Speed_Toggle := !PPSSPP_Speed_Toggle

      ;Tooltip, PPSSPP_Speed_Toggle: %PPSSPP_Speed_Toggle%
      ;Sleep 300

      ;Sleep 150   ; or Sleep 110
      Sleep 50


      JoyX_has_Reset_PPSSPP := 0


      While PPSSPP_Speed_Toggle
      {

         If WinActive("ahk_class PPSSPPWnd")   ; PPSSPP window is active
         {

            ; Without Sleep the Toggle does not work because it doesn't have time to act, the Up arrow will be pressed continuously
            ; And the toggle cannot interrupt the Up arrow key press



            Send {Up down}
            Sleep 50


            ;Tooltip, Up loop start - PPSSPP_Speed_Toggle: %PPSSPP_Speed_Toggle%
            ;Sleep 200




            ; use the Down arrow key for to change the game to normal speed and disable the speed increase

            if ( GetKeyState("Down", "p") == True)
            {
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }


            ; You may also want to use the v key for the x (cross) button on the controller for selecting - disable speed increase if v is pressed

            ; use the f key  - disable speed increase if v is pressed
            if ( GetKeyState("f", "p") == True)
            {
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }

            ; use the b key for the O (circle) button on the controller for selecting - disable speed increase if b is pressed

            if ( GetKeyState("b", "p") == True)
            {
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }


            ; use the v key for the cross (or X) button on the controller - disable speed increase if v is pressed

            if ( GetKeyState("v", "p") == True)+
            {
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }


            ; use the r key for the square button on the controller - disable speed increase if r is pressed

            if ( GetKeyState("r", "p") == True)
            {
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }



            ; use the t key for the triangle button on the controller - disable speed increase if t is pressed

            if ( GetKeyState("t", "p") == True)
            {
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }



;            ; use the Cross (or X) key on the controller to change the game to normal speed and disable the speed increase
;
;            GetKeyState, joy1_cross, 1joy1       ;1joy1 means Joystick 1 (the first 1 or 1joy1) and button joy1 which is the Cross (or X) button
;            if joy1_cross = D    ; the 1joy1 button is down
;            {
;               PPSSPP_Speed_Toggle := 0
;               Send {Up up}
;            }



            ; use the Circle key on the controller to change the game to normal speed and disable the speed increase

            GetKeyState, joy1_circle, 1joy2       ;1joy2 means Joystick 1 (the first 1 or 1joy2) and button joy2 which is the Circle button
            if joy1_circle = D    ; the 1joy2 button is down
            {
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }



            ; use the Square key on the controller to change the game to normal speed and disable the speed increase

            GetKeyState, joy1_square, 1joy3       ;1joy3 means Joystick 1 (the first 1 or 1joy3) and button joy3 which is the Square button
            if joy1_square = D    ; the 1joy3 button is down
            {
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }


            ; use the Triangle key on the controller to change the game to normal speed and disable the speed increase

            GetKeyState, joy1_triangle, 1joy4       ;1joy4 means Joystick 1 (the first 1 or 1joy4) and button joy4 which is the Triangle button
            if joy1_triangle = D    ; the 1joy4 button is down
            {
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }


            ;Tooltip, Up loop - bottom - PPSSPP_Speed_Toggle: %PPSSPP_Speed_Toggle%
            ;Sleep 300



            ; use Left Thumbstick move right to disable the speed increase started by the Up arrow button
            if JoyX >= 55.0
            {
               Send {Up up}
               Sleep 50
   
               JoyX_has_Reset_PPSSPP := 0
               PPSSPP_Speed_Toggle := 0
            }



            ;LButton_state := GetKeyState("LButton")
            ;RButton_state := GetKeyState("RButton")
            ;ToolTip, window_LButton: %LButton_state% `r`nwindow_RButton: %RButton_state% 



            ; if the left mouse is pressed (for example to click the PPSSPP menu), disable the speed increase
            ; it doesn't work very well wen clicking on the menu items instead of the main window
            LButton_State := GetKeyState("LButton", "p")
            RButton_State := GetKeyState("RButton", "p")

            if ( LButton_State == True or RButton_State == True)
            {
               PPSSPP_Speed_Toggle := 0
               Send {Up up}
            }


         } ; end for If WinActive("ahk_class PPSSPPWnd")



         ; stop the automatic key press if the focus is moved  to another application window
         else
         {
            PPSSPP_Speed_Toggle := 0
         }


      } ; end >  While PPSSPP_Speed_Toggle


   }   ; end > else if (PPSSPP_Speed_Toggle_Joy == 0)

return   ;return for R1 button> joy6::




Return   ;Return for #IfWinActive, ahk_exe PPSSPPWindows64.exe
}





; THE FOLLOWING CODE LINES ARE NOT NEEDED FOR THE SPEED TOGGLE, I PUT THIS IN ORDER FOR YOU TO SEE HOW TO USE THE SCRIPT CODE WITH OTHER PROGRAMS


    ;Console - cmd.exe
;#IfWinActive, ahk_class ConsoleWindowClass
;
;!F4::
;   WinClose, A
;   return
;#If

Attachments
AutoHotkey.ahk
code file
(86.89 KiB) Downloaded 804 times

Return to “Gaming Scripts (v1)”