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

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
}

Related

Autohotkey, problems redefining keypress down state of mousekey

I am using the LButton (mouse left) in a keybind as a prefix key. I got it to work, problem is I now need to redefine the LButton as whatever it was in it's natural state...in Autohotkey's terms.
I read this: https://www.autohotkey.com/docs/commands/GetKeyState.htm.
And cameup with the following code, but it's not working at all the way I thought it would. Simply put, you can use $LButton::Send {Click Left} to emulate the basic mouse click. The problem is when you hold the button/key down, nothing happens. I thought the code to emulate, or define the 'pressed down' behaviour would be readily available, but what I've found isn't working.
$LButton::
if (GetKeyState("LButton", "P"))
Send, {Click Left Down} ;tried variants with {Click Left} etc alrdy
else
Send, {Click Left Up}
return
For person in comments:
LButton & ~RButton::
Send, 1{Click Right}{Click Left}{Click Right}{MButton}
Sleep 130 ;125
Send, 1
return
$LButton:: ;no idea what this shud be
SendInput {Click Left}
;Send, {Click Left Down}
;KeyWait, LButton
;Send, {Click Left Up}
return
RButton::
Send, 1{Click Right}{Click Left}{Click Right}{MButton}
Sleep 130 ;125
Send, 1
return
Not sure if I understood this correctly, but you want holding LButton, then clicking the RButton to run this code:
Send, 1{Click Right}{Click Left}{Click Right}{MButton}
Sleep 130 ;125
Send, 1
And just clicking RButton should run that code as well?
And if LButton is just pressed normally (not in combination with RButton) it should function as normal?
Well this would be it:
~LButton & RButton::
RButton::
Send, 1{Click Right}{Click Left}{Click Right}{MButton}
Sleep, 130
Send, 1
return
Basically just making use of the ~ modifier.
Although I can't speak for Send, 1{Click Right}{Click Left}{Click Right}{MButton}.
I don't know what it's supposed to do, but maybe/hopefully it's doing the right thing.
Pressing w or something that you define should do the job
w::
Send, {Click down}
Send, {Blind}1{Click Right}{Click}{Click Right}{MButton}
Sleep 130 ;125
Send, 1
return
Anyone looking for something similar could try in this direction
#SingleInstance force
#warn
r::Reload
x::ExitApp
w::
Send, {Click down}
Send, {Blind}1{Click Right}{Click}{Click Right}{MButton}
Sleep 130 ;125
Send, 1
return
just Pressing w should do the job
Alternately
, the below one will do the same
LButton::Send, {Click down}
RButton::
if GetKeyState("LButton", "P")
{
Send, {Blind}1{Click Right}{Click}{Click Right}{MButton}
Sleep 130 ;125
Send, 1
}
else
Send, {Click Right}
return

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

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