Delay pixel search - autohotkey

f1::
enterPixelSearch,x1,y1,1,100,200,100,0x000000,2,Fast RGB
if(ErrorLevel == 0)
{
sleep, 20
send
}
How do I add a sleep to the enterpixel search itself? I want to delay the function after pressing the hotkey

Something like this?:
f1::
Sleep 1000
enterPixelSearch,x1,y1,1,100,200,100,0x000000,2,Fast RGB if(ErrorLevel == 0) { sleep, 20 send }
return

Related

How to Randomize Text in AHK

I am looking to send three different messages every 10 seconds, currently this is what I have but it is not working. As you can see, every 10 seconds I am getting a random int between 1 and 3 and then using if statements to send the corresponding number. Then from there that should send the text.
{
Sleep, 10000 ;
Random, Rand, 1, 3 ;
}
if (Rand == 1)
{
Send {1}
Send {Enter}
}
if (Rand == 2)
{
Send {2}
Send {Enter}
}
if (Rand == 3)
{
Send {3}
Send {Enter}
}
1::
send, test 1
return
2::
send, test 2
3::
send, test 3
Esc::ExitApp
First I don't see that your script is looping, so it runs once and finishes. Then I don't think the bit at the end is needed unless you are specifically wanting to be able to manually press 1, 2 or 3 and have them do something, but that was not mentioned as being your intention.
Try something like this:
stopit = 0
While stopit = 0
{
Loop, 50
{
if stopit = 1
{
ExitApp
}
Random, Rand, 1, 3
if (Rand == 1)
{
Send {1}
Send {Enter}
}
if (Rand == 2)
{
Send {2}
Send {Enter}
}
if (Rand == 3)
{
Send {3}
Send {Enter}
}
Sleep, 5000
}
}
return
F10::
stopit = 1
return
Esc::
ExitApp
To repeat an action periodically (at a specified time interval) you need a timer or a Loop as in the other answer.
AFAIK SetTimer has higher performance than a Loop and consumes less resources.
#NoEnv
#SingleInstance Force
#UseHook
SetTimer, send_random_text, 10000 ; every 10 seconds
Return
send_random_text:
Random, Rand, 1, 3
if (Rand == 1)
GoSub 1 ; jump to this hotkey label (1::)
if (Rand == 2)
GoSub 2
if (Rand == 3)
GoSub 3
Return
1::send, test 1{Enter}
2::send, test 2{Enter}
3::send, test 3{Enter}
Esc::ExitApp

Detect F key press after holding right mouse button

I am trying to write a script that detects Right Mouse Click being held for at least 1.5 seconds and then the F key being pressed down while Right Mouse Click is still being held.
I tried the following:
Loop
{
Send, {F Down}
Sleep 2000
Send, {F Up}
sleep 1500
}
return
^F::Pause
I realized this is only a timer and does not detect which keys were pressed. How do I write a script that achieves functionality described above?
loop
{
Key := GetKeyState("rbutton")
while(Key = 0)
{
Key := GetKeyState("rbutton")
sleep,100
}
while(Key = 1)
{
sleep,100
loopnmb := A_Index
if(loopnmb = 8) ;;this number changes the length rbutton has to be pressed before F key activates
{
Key := GetKeyState("rbutton")
while(Key = 1)
{
Send, {F Down}
Key := GetKeyState("rbutton")
if(Key = 0)
{
Send, {F Up}
break
}
}
}
}
}
Timer is a little bit off so play around with it.

How do I create while loop in autohotkey that breaks when I press {Ctrl}?

I have the following while-loop in autohotkey inside a function:
foo(){
counter:=1
while(counter<10)
{
send, %counter%
Random, SleepAmount, 2300, 3300
sleep, 3000
counter++
}
}
I want the ability to stop the loop by pressing {Ctrl}. What's the best way to accomplish my goal?
Try it this way:
F1:: foo()
foo(){
counter := 1
while(counter < 10)
{
send, %counter%
Random, SleepAmount, 23, 33
loop 100
{
Sleep, %SleepAmount%
If GetKeyState("Ctrl", "P")
return
}
counter++
}
}
~Ctrl::counter := 10
F1:: foo()
foo(){
global counter:=1
while(counter<10)
{
send, %counter%
Random, SleepAmount, 2300, 3300
sleep, SleepAmount
counter++
}
}

Is Autohotkey able to perform sequential pastes?

Is it possible to create a script for the multiple successive pastes?
Example: I copy ten different words with Ctrl+C (10 times) and paste into my doc pressing Ctrl+V (10 times).
Just for fun:
copiedText := []
~^C::
ClipWait, 0
copiedText.push(clipboard), clipboard := ""
return
^V::sendInput % copiedText.length() ? copiedText.remove(1) : _
something like this
loop,
{
position = 0
loop,
{
~^c::
if (a_index = 9){
position = 0
}
else
{
position := position + 1
}
ClipWait
var%position% := clipboard
return
}
::p1::
send, %var1%
return
::p2::
send, %var2%
return
::p3::
send, %var3%
return
::p4::
send, %var4%
return
::p5::
send, %var5%
return
::p6::
send, %var6%
return
::p7::
send, %var7%
return
::p8::
send, %var8%
return
::p9::
send, %var9%
return
::p10::
send, %var10%
return
}
save clipboard into var then input them where and how you like to.

Getting variable type in Autohotkey

Why does this work to determine the type
if delay is integer
{
MsgBox You set delay = %delay% seconds
return
}
else
{
MsgBox "%delay%" is not a valid number.
goSub, input
}
But not this - this also allowes non integer values, as long as it's greater than 0
if (delay is integer and delay > 0)
{
MsgBox You set delay = %delay% seconds
return
}
else
{
MsgBox "%delay%" is not a valid number.
goSub, input
}
Both snippets are for checking the result of an input box. The script is meant to help extracting a movie or sth. while u still download and already watching it after having finished the first part or so..
Here's the full script in case someones interested.
delay := 120
help = Help - Unzip Auto Extractor`nF1: Help`nF2: Get Unzip Window`n(must be in foreground)`nF3: Set unpack delay (seconds, default 120)`nF4: Start or stop unpacking`nF5: Exit
MsgBox %help%
F1::
MsgBox %help%
return
F2::
WinGetTitle, title, A
MsgBox Selected window "%title%"
return
F3::
input:
InputBox, delay, Set extraction timeout in seconds..,Use numbers only,,,,,,,,%delay%
;InputBox, OutputVar [, Title, Prompt, HIDE, Width, Height, X, Y, Font, Timeout, Default]
if delay is integer
{
MsgBox You set delay = %delay% seconds
return
}
else
{
MsgBox "%delay%" is not a valid number.
goSub, input
}
#MaxThreadsPerHotkey 3
F4::
#MaxThreadsPerHotkey 1
if KeepWinZRunning
{
KeepWinZRunning := 0
return
}
else
{
KeepWinZRunning := 1
}
Loop
{
Loop %delay%
{
sleep 1000
if not KeepWinZRunning
{
break
}
}
if not KeepWinZRunning
{
break
}
ControlSend,,{Enter},%title%
}
KeepWinZRunning := 0
return
F5::
ExitApp
return
I think this quote from autohotkey If var is [not] type documentation will answer your question:
Note: The operators "between", "is", "in", and "contains" are not supported in expressions.
Note the second example work fine for me regardless of this rule.