script won't run a section of code - autohotkey

I have this small script that is supposed to open up an app and type in some letters. However, for some reason the script won't run a section of code. It gets up to winMaximize and then stops. But if the app is already open then the section DOES run?? Not sure if I'm doing anything wrong, ideas?
#NoEnv
CoordMode, Mouse, Window
SendMode Input
#SingleInstance Force
SetTitleMatchMode 2
#WinActivateForce
SetControlDelay 1
SetWinDelay 0
SetKeyDelay -1
SetMouseDelay -1
SetBatchLines -1
;if 0 < 2 ; The left side of a non-expression if-statement is always the name of a variable.
;{
; MsgBox, This script requires 2 incoming parameters but it only received %0%.
; ExitApp
;}
IfWinNotExist, ahk_exe photoscan.exe
{
RunWait, "C:\Program Files\Agisoft\PhotoScan Pro\photoscan.exe"
}
WinActivate ; Automatically uses the window found above.
sleep,5
WinMaximize
;Macro5:
Click, 499, 426, 0
Click, 497, 427, 0
Click, 496, 427, 0
Click, 493, 428, 0
Click, 492, 429, 0
Click, 487, 431, 0
Click, 485, 433, 0
Click, 482, 435, 0
Click, 481, 435, 0
Click, 480, 435, 0
Click, 479, 436, 0
Click, 478, 436, 0
Click, 477, 437, 0
Click, 477, 438, 0
Click, 476, 438, 0
Send, {LControl Down}
Send, {r}
Click, -56, 157, 0
WinActivate, Run Python Script ahk_class QWidget
Send, {LControl Up}
Send, {LControl Down}
Send, {LControl Up}
Send, {LControl Down}
Send, {a}
Send, {LControl Up}
Send, {Backspace}
Send, {%1%} ; 1st argument is the images folder directory
Send, {Tab}
Send, {Tab}
Send, {LControl Down}
Send, {%2%} ; 2nd argument is additional args (in our case, the projectName)
Send, {LControl Up}
Send, {Backspace}
Send, {b}
Sleep, 703
Send, {Enter}
Click, 476, 438, 0
Return

By ommitting any wintitle parameters, you are calling winactivate and winmaximize on the "The Last Found Window". I think winMaximize simply doesn't execute because there was just no found window (it is called "the last found window", and not "the window which was found last, or maybe it wasn't").
Afaican see, your stack trace is
>
> IfWinNotExist, ahk_exe photoscan.exe ; does not exist. -> last found window: NONE
> RunWait, "C:\Program Files\Agisoft\PhotoScan Pro\photoscan.exe"
> ; still: last found window: NONE
> WinActivate / WinMaximize ; called on NONE
Not sure why winActivate terminates though. Either way, if you add ahk_exe photoscan.exe to winactivate and winmaximize, you should be fine

Related

Need help on AHK script closing when pixel change

Hello I am fairly new to coding and I’m making a programme for a game I play on AHK, I’m trying to code a script so that when a pixel changes colour on my screen the script will completely stop whilst remaining part of the loop. The main code works but I've tried to add a system where the script will stop running if a pixel changes colour. Thanks for the help in advance.
Esc::ExitApp
+r::
sleep, 1000
Send, {e down}
Send, {e up}
sleep, 10750
loop {
PixelGetColor, color1, 949, 269
if(color1 = “0xA6A6A6”)
sleep, 500
SendInput {Esc}
IfWinActive ahk_exe FiveM_GTAProcess.exe
sleep, 5550
Send, {e down}
Send, {e up}
sleep, 500
MouseClick Left, 649, 390
sleep, 500
MouseClick Left, 964, 484
sleep, 500
MouseClick Left, 1311, 415
sleep, 500
loop, 4
{
MouseClick Left, 964, 484
sleep, 500
}
sleep, 500
MouseClick Left, 720, 415
sleep, 500
}
Add Break after your if:
if(color1 = “0xA6A6A6”)
Break
if(color1 = “0xA6A6A6”)
{
sleep, 500
SendInput {Esc}
}

How to change the loop?

The script is searching for a certain text in the clipboard. When found, it shows a MsgBox.
I would like this script to stop when the text has been found. How to achieve that?
#Persistent
MouseMove, 821, 700
Sleep, 500
MouseClick, Left
Sleep, 500
Loop, 5
{
Send, ^c
Sleep, 500
Send, {PgDn}
}
OnClipboardChange:
If InStr( Clipboard, "Part3" )
SetTimer, PopupMsgBox, -1
Return
PopupMsgBox:
Msgbox, Part3 Found
Return
#Persistent
clip_search := "Part3"
MouseMove, 821, 700
Sleep, 500
MouseClick, Left
Sleep, 500
Loop, 5
{
Send, ^c
ClipWait
If InStr( Clipboard, clip_search )
{
MsgBox, % clip_search " Found."
Break
}
Sleep, 500
Send, {PgDn}
}

I cant seem to run a AHK script ONLY when I insert the sd card

I have been looking into this for a few days ♫ And i still haven't found what I'm looking for♫ The problem is that the script runs when I insert the sd card AND when I take it out. Any suggestions to how I could get it to just run on insert?
Code:
#Persistent
OnMessage(0x219, "notify_change")
notify_change(wParam, lParam, msg, hwnd)
{
send, <#{right}
sleep, 100
MouseClick, left, 726, 615
send, ^a
sleep, 100
send, ^c
sleep, 100
GroupAdd, ExplorerGroup,,ShellView
GroupActivate ExplorerGroup
send, ^v
return
}

AutoHotKey - Looping through file dosen't stop after file ends, Send not sending variable

So this is my very first AHK program and I am not at all familiar with the language. I am familiar with C# though. I have the following `program that loops trough a file and splits a username and password split by a pipe (|) symbol. Right now when I run the program, it does not stop looping after the end of the file.
In addition, I try to access the username and password separated by the pipe symbol using the StrSplit function. so far, when I run the program, the username is only sometimes enteredcorrectly into the browser. The password is not entered into the browser. I am pretty sure `I am using the right mouse coordinates.
Thanks in advance` for the help!
#SingleInstance, Force
SetWorkingDir, %A_ScriptDir% ; if an absolute path isn't specified
;; GUI input
;-------------------------------
; ---------------------------------------
Gui, Add, Button, x10 y20 gStart, Start the tool
Gui, Show, w300 h300, Steam Tool
return
; Labels
; -----------------------
; --------------------------------
Start:
Loop, read, accounts.txt ; the file name must be separated by a comma
{
; MsgBox %A_LoopReadLine%
loop, parse, A_LoopReadLine,
{
IfWinNotExist, Multiloginapp - 01.3.15
{
Run, C:\Program Files (x86)\Multiloginapp\multiloginapp.exe
WinWait, Multiloginapp - 01.3.15
Sleep, 20000
}
IfWinNotActive, Multiloginapp - 01.3.15, ,WinActivate, Multiloginapp - 01.3.15
WinWaitActive, Multiloginapp - 01.3.15
Click 724, 260
sleep, 1500
WinWait, Multiloginapp - Mozilla Firefox
WinActivate, Multiloginapp - Mozilla Firefox
WinWaitActive, Multiloginapp - Mozilla Firefox
Click 408, 55
Sleep 5000
Send, ^a
Send, {Backspace}
SendInput, store.steampowered.com/account ; SendInput is faster in sending text
Send, {enter}
Sleep, 5000
; Use:
; SendInput, %A_LoopField%
; if you want to send the current substring (field) from the line
s:=StrSplit(A_LoopReadLine, "|")
Click, 149, 355
urnme := s[0]
Send, %usrnme%
Click, 172 455
pwd := s[1]
Send, %pwd%
Click, 87 507
}
}
return
Try it this way:
#SingleInstance, Force
SetWorkingDir, %A_ScriptDir% ; if an absolute path isn't specified
;; GUI input
;-------------------------------
; ---------------------------------------
Gui, Add, Button, x10 y20 gStart, Start the tool
Gui, Show, w300 h300, Steam Tool
return
; Labels
; -----------------------
; --------------------------------
Start:
IfWinNotExist, Multiloginapp - 01.3.15
{
Run, C:\Program Files (x86)\Multiloginapp\multiloginapp.exe
WinWait, Multiloginapp - 01.3.15
Sleep, 20000
}
IfWinNotActive, Multiloginapp - 01.3.15, ,WinActivate, Multiloginapp - 01.3.15
WinWaitActive, Multiloginapp - 01.3.15
Click 724, 260
sleep, 1500
WinWait, Multiloginapp - Mozilla Firefox
WinActivate, Multiloginapp - Mozilla Firefox
WinWaitActive, Multiloginapp - Mozilla Firefox
Click 408, 55
Sleep 5000
Send, ^a
Send, {Backspace}
SendInput, store.steampowered.com/account ; SendInput is faster in sending text
Sleep, 300
Send, {enter}
Sleep, 5000
; If the title of the window changes after this, you should use:
; WinWait, new title
; WinActivate, new title
; WinWaitActive, new title
Click, 149, 355
; ... continue using one of the next options
; ...
return
First option - Send username and password directly (without reading a file):
SendInput, username
Sleep, 300
Click, 172, 455 ; or Send, {Tab} if it activates the password field
Sleep, 300
SendInput, password
Click, 87, 507 ; or Send, {enter} if it activates the log-in field
Second option - If you have to read username and password from a file:
FileReadLine, OutputVar, accounts.txt, 1 ; If username|password (without spaces) is the first line in this file
usrnme := StrSplit(OutputVar,"|").1
pwd := StrSplit(OutputVar,"|").2
SendInput, %usrnme%
Sleep, 300
Click, 172, 455 ; or Send, {Tab} if it activates the password field
Sleep, 300
SendInput, %pwd%
Sleep, 300
Click, 87, 507 ; or Send, {enter} if it activates the log-in field

Wait for previous process to finish before starting new one

I need to find a way in AHK to wait for a program to finish, before starting a new one.
Basically, I have a script that opens an application and inputs some parameters. The application then spends an unknown amount of time processing the input data.
Unfortunately, at the moment the ahk script ends before the application has finished processing, at which point the same ahk script is run again and does not work / interrupts the previous processing.
edit: (the ahk .exe is called using subprocess calls in Python)
is there a way or any methods to help with this?
For reference, the script:
#NoEnv
CoordMode, Mouse, Window
SendInput Mode Input
#SingleInstance Force
SetTitleMatchMode 2
#WinActivateForce
SetControlDelay 1
SetWinDelay 0
SetKeyDelay -1
SetMouseDelay -1
SetBatchLines -1
if 0 < 2 ; The left side of a non-expression if-statement is always the name of a variable.
{
MsgBox, This script requires 2 incoming parameters but it only received %0%.
ExitApp
}
IfWinNotExist, ahk_exe photoscan.exe
{
Run, "C:\Program Files\Agisoft\PhotoScan Pro\photoscan.exe"
}
sleep, 200
WinActivate, ahk_exe photoscan.exe
sleep,5
WinMaximize, ahk_exe photoscan.exe
;Macro5:
Click, 476, 438, 0
SendInput {LControl Down}
SendInput {r}
Click, -56, 157, 0
WinActivate, Run Python Script ahk_class QWidget
sleep, 400
SendInput {LControl Up}
SendInput {LControl Down}
SendInput {a}
SendInput {LControl Up}
sleep, 400
SendInput {Backspace}
SendInput %1% ; 1st argument is the photoScan API scriptimages folder directory
SendInput {Tab}
SendInput {Tab}
sleep, 400
SendInput {LControl Down}
SendInput {a} ; 2nd argument is additional args (in our case, the projectName)
SendInput {LControl Up}
SendInput {Backspace}
SendInput %2% ; 2nd argument is the images folder directory & name of output log, model and texture
Sleep, 703
SendInput {Enter}
Click, 476, 438, 0
Return
You have:
IfWinNotExist, ahk_exe photoscan.exe
{
Run, "C:\Program Files\Agisoft\PhotoScan Pro\photoscan.exe"
}
sleep, 200
Which is set to start/launch the application if it is not running. Then a sleep to allow two tenths of a second for it to load (which is probably too small).
Instead of just a ‘sleep’ you have to ‘WinWait’ or ‘WinWaitActive’, found at this link:
https://autohotkey.com/docs/commands/WinWaitActive.htm
Like this sample:
Run, "C:\Program Files\Agisoft\PhotoScan Pro\photoscan.exe"
WinWaitActive, ahk_exe photoscan.exe, , 2
if ErrorLevel
{
MsgBox, WinWait timed out.
return
}
else
WinMinimize ; minimize the window found by WinWaitActive.
You may also have to use the window inspector to get the true name of the window/application/process name.