How to change the loop? - autohotkey

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

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

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 Clicking Script

I've only just started with AutoHotKey, and I'm looking to make a script that will click once per second 10 times, then hold right mouse button for 3 seconds, before resetting. I intend it to active on alt+c, and break if I press the left mouse button.
The script I came up with it
LButton::
BreakLoop = 1
return
!c::
Loop
{
if (BreakLoop = 1)
break
;
Click
Sleep, 1000
Click
Sleep, 1000
Click
Sleep, 1000
Click
Sleep, 1000
Click
Sleep, 1000
Click
Sleep, 1000
Click
Sleep, 1000
Click
Sleep, 1000
Click
Sleep, 1000
Send, {RButton Down}
Sleep, 3000
Send, {RButton Up}
Return
}
However, this is not working. Is there a way to fix this, or have I taken the completely wrong approach for this script?
You did make a Mistake in the code, On the Bottom You did have the Return Command into the Loop that is not possible. (This Return Command Will be needed for !c:: and it must outsite the loop command)
The Code must be Like:
~LButton::
BreakLoop = 1
return
!c::
Loop
{
if (BreakLoop = 1)
break
Click
Sleep, 1000
Click
Sleep, 1000
Click
Sleep, 1000
Click
Sleep, 1000
Click
Sleep, 1000
Click
Sleep, 1000
Click
Sleep, 1000
Click
Sleep, 1000
Click
Sleep, 1000
Send, {RButton Down}
Sleep, 3000
Send, {RButton Up}
}
Return
Tip: if you change Lbutton:: into ~Lbutton:: then The Default LeftButton is also active.
I was actually able to find a way to compact it significantly (and break the loop faster) by nesting a loop within a loop
!s::
BreakLoop = 1
return
!c::
BreakLoop = 0
Loop
{
Loop 10
{
if (BreakLoop = 1)
break
;
Click
Sleep, 900
}
Send, {RButton Down}
Sleep, 3000
Send, {RButton Up}
}
if (BreakLoop = 1)
Break
;
Return
A better method is to use SetTimer, this allows you to break out of the loop at any point in your sequence of actions.
Try:
!c::setTimer, doAction, 1000
!s::SetTimer, doAction, Off
doAction:
i += (i <= 14 ? 1 : -13)
if (i == 14)
send, {RButton Up}
else if (i == 11 )
Send, {RButton Down}
else if (i <= 10)
click
return

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.

Manipulate a webpage to include a watermark

I work with a web application that works only on Mozilla Firefox.
A particular task generates a page to print a letter to be mailed.
After printed the letter, my colleagues should stamp the brand of post office and manually write the send date on which the letter is sent.
Is there any way to manipulate the display of the page to include a line in HTML with the stamp image before printing?
Any ideas?
Thank you very much.
Is there any reason it needs to be done via autohotkey? If you have access to the code, you could just add a print stylesheet that overlays the stamp image.
SmashingMagazine has a fantastic guide to print stylesheets:
In essence, all you have to do is add this to your existing stylesheet:
#media print {
//css to add the stamp image overlay here
}
Thanks for feedback.
I figured it out.
That's my code:
#NoEnv
#Persistent
#SingleInstance force
SendMode Input
SetWorkingDir %A_ScriptDir%
Gui, Add, Button, gCorreios, Correios
Gui, Show
Return
Correios:
Sleep 100
Send, {ALT DOWN}{ESC}{ALT UP}
Send, {CTRLDOWN}f{CTRLUP}
Sleep 10
Send, Postado{ESC}
Sleep 10
Send, {SHIFTDOWN}{END}{SHIFTUP}{CTRLDOWN}c{CTRLUP}
ClipWait
Sleep 10
DataDaPostagem=%Clipboard%
ClipBoard =
Sleep 10
StringReplace, DataDaPostagem, DataDaPostagem, postado,, All
StringReplace, DataDaPostagem, DataDaPostagem, em,, All
StringReplace, DataDaPostagem, DataDaPostagem, :,, All
StringReplace, DataDaPostagem, DataDaPostagem, `,,, All
StringReplace, DataDaPostagem, DataDaPostagem, %A_SPACE%,, All
Sleep 10
Send, {SHIFT DOWN}{F4}{SHIFT UP}
WinWait, Scratchpad,
IfWinNotActive, Scratchpad, , WinActivate, Scratchpad,
WinWaitActive, Scratchpad,
Send, {CTRLDOWN}a{CTRLUP}{DEL}
Send, var correios=document.createElement("div");{ENTER}
Send, correios.id="correios";{ENTER}
Send, correios.style="background:url(http://i62.tinypic.com/169hxls.png) no-repeat; display:block; height:37px; padding:135px 0 0 0; position:absolute; right:0; text-align:center; top:0; width:171px; z-index:-1";{ENTER}
Send, correios.innerHTML="
Send, %DataDaPostagem%
Send, ";{ENTER}
Send, document.getElementsByTagName("body")[0].appendChild(correios);{ENTER}
Send, {CTRLDOWN}r{CTRLUP}
Sleep 10
Send, {CTRLDOWN}w{CTRLUP}
WinWait, Alterações não salvas,
IfWinNotActive, Alterações não salvas, , WinActivate, Alterações não salvas,
WinWaitActive, Alterações não salvas,
Send, d
Sleep 10
return
~^s::
IfWinActive, %A_ScriptName%
{
SplashTextOn,,,Updated script,
Sleep, 200
SplashTextOff
Reload
}
return