Getting variable type in Autohotkey - 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.

Related

check if key variable is equal to button

i wanna click a random button 50 times from a list unless it is 1 only click it once, its always going to the else even if key is 1
!F2::
breakvar = 1
return
!F1::
loop
{
Random, var, 1,7
keyList = {1},{2},{3},{w},{a},{s},{d}
StringSplit, KeyAry, KeyList, `,,%A_Space%
key := KeyAry%var%
loop 50
{
; i've tryied:
;(%key% = "1")
;(key = 1)
;(key = {1})
; but with out success
if (key = "1")
{
Send, %key%
break
}
else
{
Send, %key%
Sleep, 100
}
}
if breakvar = 1
break
}
breakvar = 0
return
also is there a better way to achieve what i am trying to do?
thx
Your main mistake was that you indeed didn't manage to get the if statement corrent. The right one would've been if (key = "{1}").
But really, I don't know why you even had the { }, it's a common mistake I see from nearly every beginner, I wonder where it comes from.
You're only supposed to use { } for escaping or if the special notation is needed for something such as {space}. Read more from the documentation.
Here's a cleaned up script with all other weirdness removed as well:
KeyList := StrSplit("1,2,3,{space},+1,w,🐈", ",") ; +1 is shift + 1 (whatever key that will produce in your keyboard layout)
!F2::BreakVar := true
!F1::
loop
{
Random, index, 1, 7
key := KeyList[index]
loop 2
{
SendInput, % key
if (key = "1")
break
Sleep, 100
}
if (BreakVar)
break
}
BreakVar := false
return
To be totally correct, I should say that you shouldn't loop under hotkeys and should use a timer instead, but I wont add that in to confuse you. This should be fine as well, if you have problems with hotkeys after this, you can look into a timer approach yourself or ask help here.

How to reset a key sequence with a specific key?

So this sequence resets itself after 1.5 sec (t:=1500) which means if i dont hit the left mouse button for 1.5 sec it always sends A. Otherwise it sends the next letter after each click.
I want to further tweak this code with another function which is to be able to reset the sequence with right mouse button too. So if i hit RButton any time it should reset to A.
Thx.
global s:=0, c:=0, t:=1500
*LButton::
Send % Seqkeys("A","B","C")
KeyWait, LButton
Send, R
return
Seqkeys(params*) {
global s, c, t
max := params.MaxIndex()
(A_TickCount-s<=t && (c+=1)<=max) ? c : c:=1
s := A_TickCount
return params[c]
}
Merely reset the current key index 'c', and the last clicked time 's':
*RButton::
c := 1
s := 0
return
I think your script would benefit with more meaningful variable names:
global lastClickedTime:=0, currentKeyIndex:=0, clickThreshold:=1500
*LButton::
Send % Seqkeys("A","B","C")
KeyWait, LButton
Send, R
return
*RButton::
currentKeyIndex := 1
clickThreshold := 0
return
Seqkeys(params*) {
global lastClickedTime, currentKeyIndex, clickThreshold
max := params.MaxIndex()
currentKeyIndex += 1
if((A_TickCount - lastClickedTime) <= clickThreshold && currentKeyIndex <= max) {
; Do nothing
} else {
currentKeyIndex := 1
}
lastClickedTime := A_TickCount
return params[currentKeyIndex]
}

Delay pixel search

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

Why when I run application it just skip some ifs

As I said text that is bolded doesn't work, it just skip it (it worked without those ifs) could you help me? Please, I'm doing that few hours but it still doesn't work. I tried to add this if not in this loop and it worked, please give me a hand, I spent so much time
on it ;(
Gui, Add, CheckBox, x405 y317 w15 h15 vwyrzucaniediax gZapisz,
Gui, Show, h500 w800, Skrypt Na Kopanie
Return
Zapisz:
Gui, Submit , NoHide
return
F8::
WinMove, Minecraft, , , , 1280, 720
sleep 1000
Loop
{
if poziome
{
}
if pionowe
{
}
Checker()
}
Checker()
{
x := 503
y := 385
l := 0
i := 0
Send e
loop, 27{
if(i = 9){
i := 0
l++
}
Sleep 100
MouseMove, x +36*i, y + 36*l
**if wyrzucaniediax // all strong text is just skipped idk why
{
Dropdiax()
}
**
i++
}
Send e
Sleep 50
}
dropdiax(){
diaxcolor := 0x80ĄFFE
color:= getColor()
if(color == diaxcolor){
Send {LCtrl down}
Send q
Sleep 50
Send {LCtrl up}
}
}```
Your wyrzucaniediax variable (maybe you could use better variable names when asking for help?) isn't defined in that function's scope.
To tell the function you're using a variable from outside of its scope, you can use the Global keyword.
Checker()
{
global wyrzucaniediax
x := 503
y := 385
l := 0

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.