I can't switch Razer profiles with my game script. Topic is solved

Ask gaming related questions (AHK v1.1 and older)
LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

I can't switch Razer profiles with my game script.

Post by LAPIII » 21 Jun 2022, 18:18

This is my game script:

Code: Select all

#SingleInstance, Force
#NoTrayIcon
#IfWinExist, ahk_exe AM4.exe

x::
MouseClick, left, 1752, 798
MouseClick, left, 1241, 283
MouseClick, left, 237, 58
MouseClick, left, 1389, 64
MouseClickDrag, L, 924, 44, 1051, 49
return

!3::
MouseClick, left, 801, 592
Send 1
;Sleep 100
MouseClick, left, 801, 592
Send 3
return

c:: ; Crash
	
MouseClick, left, 1272, 486
MouseClick, left, 237, 58
return

m::MouseClick, left, 1518, 1042 ; Music

Space::MouseClick, left, 1318, 1047 ; Pause

; Difficulty

6::MouseClickDrag, L, 924, 44, 967, 49
7::MouseClickDrag, L, 924, 44, 1012, 49
8::MouseClickDrag, L, 924, 44, 1051, 49
9::MouseClickDrag, L, 924, 44, 1099, 49
0::MouseClickDrag, L, 924, 44, 1158, 49

And I tried to put at the top (Below #IfWinExist, ahk_exe AM4.exe):

Code: Select all

CoordMode, mouse, screen
Click 1756 1053
Sleep 800
MouseMove, 1885, 768
Click 1597 761 ; Airport Madness

And at the bottom:

Code: Select all

WinWaitClose ahk_exe AM4.exe
Click 1756 1053
Sleep 800
MouseMove, 1885, 768
Click 1530 871 ; General Profile
MsgBox, switch to the general profile

User avatar
boiler
Posts: 16915
Joined: 21 Dec 2014, 02:44

Re: I can't switch Razer profiles with my game script.

Post by boiler » 22 Jun 2022, 05:33

You can’t put that code at the bottom or it will never execute because it’s below hotkeys and therefore not in the auto-execute section. Put it right underneath the other stuff you put at the top.

You really should study and understand the whole Structure of a Script section if this isn’t clear to you at this point. You need to be able to trace how the code would flow line by line in your scripts.

LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: I can't switch Razer profiles with my game script.

Post by LAPIII » 22 Jun 2022, 08:28

As soon as I ran this script, without starting the game, and it changed to both profiles:

Code: Select all

#SingleInstance, Force
#NoTrayIcon
#IfWinExist, ahk_exe AM4.exe

CoordMode, mouse, screen
Click 1756 1053 ; click notification area icon
Sleep 1000
Click 1885 768 ; hover over the arrow
Click 1522 753 ; Airport Madness

WinWaitClose ahk_exe AM4.exe
Click 1756 1053 ; click notification area icon
Sleep 1000
Click 1885 768 ; hover over the arrow
Click 1522 753 ; open menu
Click 1530 871 ; General Profile

x::
MouseClick, left, 1752, 798
MouseClick, left, 1241, 283
MouseClick, left, 237, 58
MouseClick, left, 1389, 64
MouseClickDrag, L, 924, 44, 1051, 49
return

!3::
MouseClick, left, 801, 592
Send 1
;Sleep 100
MouseClick, left, 801, 592
Send 3
return

c:: ; Crash
	
MouseClick, left, 1272, 486
MouseClick, left, 237, 58
return

m::MouseClick, left, 1518, 1042 ; Music

Space::MouseClick, left, 1318, 1047 ; Pause

; Difficulty

6::MouseClickDrag, L, 924, 44, 967, 49
7::MouseClickDrag, L, 924, 44, 1012, 49
8::MouseClickDrag, L, 924, 44, 1051, 49
9::MouseClickDrag, L, 924, 44, 1099, 49
0::MouseClickDrag, L, 924, 44, 1158, 49

User avatar
boiler
Posts: 16915
Joined: 21 Dec 2014, 02:44

Re: I can't switch Razer profiles with my game script.

Post by boiler » 22 Jun 2022, 12:52

Then put a WinWait before the WinWaitClose. Then it will wait for it to be open then for it to close before doing that stuff.

LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: I can't switch Razer profiles with my game script.  Topic is solved

Post by LAPIII » 24 Jun 2022, 15:51

The script didn't work. My workaround was to make a script switch the profile, launch the game, and then switch the profile back. I compiled that script, made a shortcut, and then change the icon via Properties.

User avatar
boiler
Posts: 16915
Joined: 21 Dec 2014, 02:44

Re: I can't switch Razer profiles with my game script.

Post by boiler » 24 Jun 2022, 16:14

You wouldn't need such a workaround if you implement the WinWait properly. Did you identify the window title with it? Where did you put it?

LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: I can't switch Razer profiles with my game script.

Post by LAPIII » 24 Jun 2022, 16:17

I did not add all the information that I should have. I'll be changing the profile via the icon in the notification area. That's why things didn't start until the actual game process did.

LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: I can't switch Razer profiles with my game script.

Post by LAPIII » 29 Jun 2022, 11:57

My script was working fine until now. It now switches profile, turns the game on, then off, and then switches the profile. All within a few seconds. I restarted my PC, but this didn't help. The WinWait that you suggested did not help nor did it taking out the BlockInput commands. Sometime today I had opened in Steam and I figured that there was an update that did something but could you take a look:

Code: Select all

#IfWinExist, ahk_exe AM4.exe
BlockInput, On
BlockInput, Mouse
CoordMode, mouse, screen
Click 1756 1053 ; click notification area icon
Sleep 1000
Click 1885 768 ; hover over the arrow
MouseMove, 1522, 753 ; open menu
Click 1522 753 ; Airport Madness 4

Run, steam://rungameid/387850

WinWaitClose ahk_exe AM4.exe
Click 1756 1053 ; click notification area icon
Sleep 1000
Click 1885 768 ; hover over the arrow
Click 1522 753 ; open menu
Click 1530 871 ; General Profile
BlockInput, Off

User avatar
boiler
Posts: 16915
Joined: 21 Dec 2014, 02:44

Re: I can't switch Razer profiles with my game script.

Post by boiler » 29 Jun 2022, 12:32

The first thing I see is that the #IfWinExist directive does nothing because that script has no hotkeys, so there’s no reason to have it in the script.

I can’t tell where you put the WinWait command or how you wrote it since it’s not in the above script. You should post the version where you added that to see if you made a mistake in trying to implement it either in where it appears or how you wrote it.

LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: I can't switch Razer profiles with my game script.

Post by LAPIII » 29 Jun 2022, 13:29

It just turns out that I had to use a MouseMove for lines 7, 8, 16 & 17. Thank you.

Post Reply

Return to “Gaming Help (v1)”