what is the function of Target:="f"5-ChampIndex? - autohotkey

Target:="f"5-ChampIndex
send {%Target% down} ;centers camera on teammate to follow
PixelSearch, ax, bx, 78, 87, 75, 87, 0x010d07, 10, Fast RGB ;checks for own HP specifically if below 65% HP
if ErrorLevel=0
I don't understand what {%Target% down} and {%Target% up} do, could someone explain?

I'd assume ChampIndex gets a value between 0 and 4, so the first line creates a variable that holds the a string like f1, f2, f3,..
Then % % is the legacy way of retrieving a variable in a legacy statement.
So you end up with send commands like send {f1 down}, which means start holding F1 down.

Related

My script breaks down at some point, I've eliminated all the syntax errors the debugger was able to spot

This is a script that is supposed to use the windows snipping tool to sequentially screencap pictures from an online gallery. If anyone can spot the problem that would be much appreciated.
#SingleInstance, Force
a := 112
name :=1
x:: Pause, Toggle
y:: ExitApp
Loop, a
{
MouseClickDrag, Left, 1300, 210, 645, 140
Sleep, 100
MouseClick, Left, 1277, 1038, 0, 5
sleep, 100
MouseClick, Left, 838, 64, 0, 5
sleep, 100
SendInput, %name%
name ++
sleep, 100
SendInput, {Enter}
Sleep, 100
MouseClickDrag, Left, 670, 13, 1393, 153
Sleep, 100
MouseClick, Left, 500, 490, 0, 5
Sleep, 300
MouseClick, Left, 500, 490, 0, 5
SendInput, {Right}
}
Two problems in it.
Firstly, your loop is unreachable code.
Code execution stops when your first hotkey label is encountered. This is called the Auto-execute Section.
Secondly, loop doesn't take an expression to the first parameter. It takes a legacy text parameter. So you'd either want to use the legacy way of referring to a variable, which would be %a%, but personally I'd push you towards using the modern expression syntax and forcing an expression to that parameter by starting the parameter off with a % followed up by a space. So Loop, % a.
To read more about legacy syntax vs expression syntax, see this page of the documentation.
Here's your fixed script:
#SingleInstance, Force
a := 112
name := 1
Sleep, 3000
Loop, % a
{
MouseClickDrag, Left, 1300, 210, 645, 140
Sleep, 100
MouseClick, Left, 1277, 1038, 0, 5
Sleep, 100
MouseClick, Left, 838, 64, 0, 5
Sleep, 100
SendInput, % name
name++
Sleep, 100
SendInput, {Enter}
Sleep, 100
MouseClickDrag, Left, 670, 13, 1393, 153
Sleep, 100
MouseClick, Left, 500, 490, 0, 5
Sleep, 300
MouseClick, Left, 500, 490, 0, 5
SendInput, {Right}
}
;this return here ends the auto-execute section
;but of course, in this specific case it's totally
;useless since the next line is a hotkey label
;which would also stop the auto-execute section
return
;even though the code execution gets stuck inside the loop,
;hotkeys can be specified down here
;they're created even before the auto-execute section starts
x::Pause, Toggle
y::ExitApp

How to pause a loop in autohotkey

I need to pause a spacebar spamming macro with a key like f10, here is my code
c::
Loop
{
if not GetKeyState("c", "P")
break
Sleep 25 ; ms
Send {space}
}
return
I tried to add a pause similar to the getkeystate in and out of the loop but to no avail.
I always do something to the extent of this:
c::
Toggle := !Toggle
While Toggle {
; do whatever you need to do here
}
Return
An additional advantage here is that there's only one hotkey to remember. Press once to begin the endless loop. Press again to stop.
q::
Loop
{
Click, right,
Mousemove, 0, 110, 5, Rel
click, left
Mousemove, 350, -473, 5, rel
click, left
Mousemove, -350, 363, 5, rel
}
return
#p::Pause,Toggle
https://autohotkey.com/board/topic/95308-endless-loop-with-hotkey-pause/

How to Send key faster with PixelGetColor / PixelSearch

I am using this code to send pot key when I press skill key
*RButton::
{
PixelGetColor, ColorOutPut, 256, 762, Fast RGB ;2 last
if (ColorOutPut = 0x090606)
{
;~ PixelGetColor, ColorOutPut, 273, 750, Fast RGB ;charge
;~ if not (ColorOutPut = 0x3A3436)
;~ {
SetKeyDelay -1,-1
Sendinput {Blind}{2 down}
SetKeyDelay -1,-1
Sendinput {Blind}{2 up}
;~ }
}
SetKeyDelay -1,-1
SendInput, {Blind}{RButton DownR}
}
return
*RButton up::
SetKeyDelay -1,-1
SendInput, {Blind}{RButton up}
return
PixelGetColor run time is 0.1-0.2 sec for me so skill is being late that time, because of it i can't send multiple PixelGetColor.
What I want to ask is how can I read color and send keys instantly and that way my skill won't be late?
And I cant send skill forward because skill gets help from pots. Thx for you support.
You may want to add 'Process, Priority,, High'. The -1/-1 are not ideal to use, most people use 'SetKeyDelay, 0'

How to use HotString with variable & wildcard?

In Onenote, let's say I want to write x^y (x to power of y), I would need to enter Equ mode (by keyboard shortcut) , type x^y , hit Space, then exit equ mode
So, I figure it could be something like this :
::(wild_card)^(wild_card)::
Send, (Shortcut for equ mode)
Send, variable1
Send, ^
Send, variable2
Send, space
Send, (Shortcut for equ mode)
How do I actually achieve this ?
Alternatively, the same purpose could be formulated by doing,
- monitor word separated by Ending chars
- detect if ^ is in those word
- Send (Shortcut) , then the word, then space, then (Shortcut).
Is this more doable ?
Thanks MCL,
Here is the code for auto convert x_y and x^y into their mathematical representation in onenote
#Include DynamicHotstrings.ahk
#IfWinActive, ahk_class Framework::CFrame
hotstrings("(\w+\_\w+) ","dowork")
hotstrings("(\w+\^\w+) ","dowork")
dowork:
Send, {LAlt Down}{=}{LAlt Up}
SendRaw, %$1%
Send, {Space}
Send, {LAlt Down}{=}{LAlt Up}
Send, {Space}
Return
Better yet , you can modify the DynamicHotstrings.ahk so it will ignore auto convert when we are already in equation mode:
hotstrings(k, a = "")
{
CoordMode,Pixel,Screen
PixelGetColor, color, 455, 1
if (color = 0xD7337F)
return
....

SendEvent ^{ins} isn't copying content to the clipboard

!c::
file_name = footnote.ini
restore_original_clipBoard := clipboard
clipboard =
KeyWait, Alt
KeyWait, c ;small c
BlockInput, on
SendEvent, ^{ins} ;^c doesn't work
ClipWait, 2 ; Wait for the clipboard to contain text.
if ErrorLevel
{
MsgBox Failed to save the selection: %clipboard%
exit
}
BlockInput, off
save_selection := clipboard
Problem: Despite a selection being made, Sendevent ^{ins} does not save it to the clipboard. Sometimes I have to repeat my hotkey, alt + c several times before the selection is being copied to the clipboard. The KeyWait should ensure me that only ^{ins} is being processed without any additional keys. What am I doing wrong here?
UPDATE
One of the ways I tried to force copy a selection to the clipboard was by using a while loop. I got it to work through the post: Looping clipboard and errorlevel evaluation not working as expected
PROBLEM
When I make a selection and press alt + c it sometimes gets stuck in the infinite loop that I implemented. But as you can see from that code:
clipboard := ""
while( StrLen(clipboard) < 1 )
{
Send, ^{ins}
Sleep, 50
}
MsgBox % ClipBoard
The infinite loop incorporates within itself a continues resending of ^{ins}. For some reason, my selection is not being recognized as a selection. Whilst it is in that infinite loop, I try to reselect the text. It then recognizes it instantly and copies my selection to the clipboard. But alas! The selection is incomplete because it goes so quick.
This problem is not always like that. Sometimes it recognizes the selection first spot on! So sometimes it copies my selection to my clipboard sometimes not. When it does not, then a resending of a ^{ins} does not seem to work. I do not want to the user to reselect his selection. Is that possible to do?
Send {Ctrl Down}{c}{Ctrl Up}
That presses Ctrl+C, you must do it instantly as one command apposed to pressing Ctrl waiting then pressing C.
Never seen Insert key used for copying text.
Also found this sends Ctrl+C as well.
Send, ^c
To send insert key use
{Insert}
This way works for me:
!vk43:: ; alt+c
clipContent:=ClipboardAll
Clipboard:=""
SendEvent, ^{Ins}
ClipWait, .75
MsgBox, % 262 . (ErrorLevel ? 160:208)
, % ErrorLevel ? "Period expired:":"Result:"
, % ErrorLevel ? "Failed to save the selection.":Clipboard
, % (ErrorLevel ? 0:2) . .5
Clipboard:=clipContent
KeyWait, vk43
Return
!vk43:: ; alt+c
clipContent:=ClipboardAll ; backup clipboard content (if needed)
Clipboard:="" ; no comment :)
Loop
{
SendEvent, ^{Ins}
ClipWait, .75 ; means 750ms, same if write 0.75
; assign value of "ErrorLevel" an variable for further usage
errLvl:=ErrorLevel
; monitoring current action (for debugging purpose only)
TrayTip, % "attempt: #"A_Index
, % """ErrorLevel"" of ""ClipWait"" command is: "errLvl
}
; here you can set the condition of ending the cycle: either...
; ...variable errLvl has not a true value,...
; ...or the number of attempts is equal 5
Until, Not errLvl Or A_Index=5
; value of each field of the command "MsgBox"...
; ...are set depending on the value of errLvl variable...
; ...using a ternary expression
; means if errLvl is a true, "options" field is 262160
MsgBox, % 262 . (errLvl ? 160:208)
; means that "title" has a couple variants
, % errLvl ? "Period expired:":"Result:"
; means that "text" has a couple variants
, % errLvl ? "Failed to save the selection.":Clipboard
; means if errLvl is a true, "timeout" field is 0.5 (500ms)
, % (errLvl ? 0:2) . .5
/* same that and above:
IfEqual, errLvl, % True, MsgBox, 262160
, % "Period expired:"
, % "Failed to save the selection."
, 0.5
Else MsgBox, 262208, % "Result:", % Clipboard, 2.5
*/
TrayTip ; remove "TrayTip" (for debugging purpose only)
; save an positive result (if needed)
IfEqual, errLvl, 0, Sleep, -1, someVar:=Clipboard
; return a temporarily saved data into clipboard (if needed)
Clipboard:=clipContent
KeyWait, % "vk43"
Return
From my experience whenever keystrokes are not recognized reliably it's due to either the system or the targeted program not keeping up with the speed at which those keys are sent.
For SendEvent you could try something like SetKeyDelay, 1000, 1000 and see if this improves things. The other option would be to send explicit down and up keys with intermittent sleep calls as outlined in this answer.