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.
Related
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]
}
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
Okay so I wrote this script in AHK to press 2 on the first press of the mouse button and 3 on the second and so on, yet it doesnt work. Any ideas why ?
XButton1::Send, 1;
XButton2::
x:=1
if (x = 1){
Send, 2
x+=1
} else if (x = 2) {
Send, 3
x+=1
} else if (x = 3) {
Send, 4
x+=1
} else if (x = 4) {
Send, 5
x = x - 3
}
Everytime you press XButton2, you reset the value of x to 1....x:=1. So it will obviously only send 2. You need to set the value of x outside of XButton2. This will work:
x := 1
XButton2::
x += 1
SendInput, %x%
return
I have a script with a list of words inside. I want to create a gui that opens up and allows users to enter words to the list and remove them aswell. Is it possible for the script to edit itself while running? If so, how would I go about doing this. Here is my current script.
Word1 = This
Word2 = Is
Word3 = A
Word4 = Test
Word5 = Script
Word6 = And
Word7 = I
Word8 = Like
Word9 = Apple
Word10 = Pie
Min := 1
Max := 10
Gui, New
Gui, Add, Text,, Please enter a word you wish to add:
Gui, Add, Edit, Word
Gui, Show
MButton::
RandWords := ""
loop,
{
Random N, %Min%, %Max%
if( Last != N )
{
Last := N
break
}
}
RandWords .= Word%N%
Send %RandWords%{!} {enter}
Return
Here is an example how to use arrays to store user input:
store :=
counter := 0
loop, 3
{
InputBox , here , User input , Please enter some text!
store%counter% := here
counter++
}
store1 = This element was deleted!
counter := 0
loop, 3
{
str := store%counter%
MsgBox, %str%
counter++
}
As you can see, store is used as a pseudo array, and is indexed using counter, or integer values.
There is a line that deletes (actually just changes, but you get the idea) the second element. It could have been written like this:
counter := 1
store%counter% = This element was deleted!
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.