mamo691 wrote: ↑03 Apr 2024, 12:54
What I want is that I want to send only one space (hold space key)+click onto the detected colour that is closest near my cursor in the range.
My code was only set to move the cursor, you would need to edit that action so that it does what you need.
Here I replaced the old "MouseMove" with a function that contains the operations to preform.
Code: Select all
;BEFORE:
MouseMove, tx , ty
;NOW:
Action_Function_1( tx , ty )
The function itself looks like this.
Code: Select all
;********************
;When the color is found it runs this code.
Action_Function_1( x , y ){ ;<--- You can "pass" as many arguments as you need to. In this example I am just passing the x and y values for where the color was found.
;~ MouseMove, x, y ;example of moving the cursor.
;~ Sleep, 500
;********************
;This is the action you asked for.
send, { Space, Down } ;hold the space key down
sleep, 30 ;wait a fraction of a second
Send, % "{ Click , " x " , " y " }" ;send a click
sleep, 30 ;wait a fraction of a second
send, { Space, Up } ;release the space key.
sleep, 30 ;wait a fraction of a second
;********************
return 1
}
;********************
I also if possible asked to be able to do combinations. Like not just this, but, like find 3 closest detected colours to my cursor in range then send each one of them only one space+click. This process will happen while I'm holding the trigger key which is "g", and when I stop holding this key, it needs to stop holding space, and stop clicking. I would very much be happy if you made this possible.
The script has been modified to use "g" as the hotkey, press it and the script will start looking for up to 3 target matches before you have to press the hotkey again.
The amount of target matches is adjustable, so for example you can set it to find 5 or 10 matches, or you can set it to have no limit by setting it to zero.
Here is the variable to find and edit.
The script works by creating a search area that radiates outwards from the cursors current position, the rate that expands is variable.
If the rate of expansion is large, the results for "closest" won't be perfect but will be with in the expansion rate.
i.e. set the rate to a value of "1" and the margin of error is 0 pixels, set the rate to 50 and the margin of error is 49 pixels.
This example shows the use of different values of the "rate" variable.
Note how the search area starts over when the cursor moves, whenever a match is found the script will reset the search area and find the next match based on the current position.
.
- pixel search range 7.gif (555.06 KiB) Viewed 309 times
.
Here are a few more thins you can adjust.
- You can adjust the number of matches to make before it stops.
- You can use a mask block if the target stays on screen.
- You can change the size of the mask blocks.
- You can set the max number of masking blocks that can be on screen before they start disappearing in sequence.
- If you don't need a mask you can comment out the 3-4 lines of code that handle displaying the block windows.
Example of adjusting the block sizes.
.
- pixel search range 8.gif (501.94 KiB) Viewed 309 times
.
Code: Select all
#SingleInstance, Force
#NoEnv
SetBatchLines, -1
CoordMode, Mouse, Screen
CoordMode, Pixel, Screen
CoordMode, ToolTip, Screen
SetWinDelay, -1
SetMouseDelay, -1
SetDefaultMouseSpeed, 0
;********************
;~ color := "0x000000"
color := "0xFD0B03"
variation := 20
range := 300
rate := 50
stop := 1
blockSize := 60
maxFinds := 3
maxblocks := 50
Delay := 10000
currentFinds:= 0
;********************
return
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&;
*ESC::ExitApp
;********************
F4:: ;{ stop script
Stop := 1
return
;}
;********************
F3:: ;{ set color variation
stop := 1
sleep, 60
InputBox, variation, Color Variation, Set the color variation`nRange: 0-255
if( variation = "" )
variation := 0
return
;}
;********************
F2:: ;{ set color
stop := 1
sleep, 60
Gui, New, +AlwaysOnTop +hwndColorGui -DPIScale -Caption +Border
While( !GetKeyState( "Ctrl" ) ){
MouseGetPos, sx , sy
ToolTip, Hover your cursor over a color and then press the "ctrl" key , % sx + 30 , % sy + 20
PixelGetColor, color, sx, sy, RGB Fast
Gui, % ColorGui ":Color", % color
Gui, % ColorGui ":Show", % "x" sx + 100 " y" sy - 30 " w" 40 " h" 40 " NA"
}
ToolTip
While( GetKeyState( "Ctrl" ) )
Sleep, 10
While( !GetKeyState( "Ctrl" ) ){
ToolTip, Move your cursor away from the color and press "ctrl" again.`nThis is mainly for cases where`nyour mouse changes the color`nthat you want when it is over it.
PixelGetColor, color, sx, sy, RGB Fast
Gui, % ColorGui ":Color", % color
Gui, % ColorGui ":Show", % "x" sx + 100 " y" sy - 20 " w" 40 " h" 40 " NA"
}
ToolTip
While( GetKeyState( "Ctrl" ) )
Sleep, 10
Gui, % ColorGui ":Destroy"
SoundBeep
SoundBeep, 600
return
;}
;********************
$g:: ;{ start search
;~ SoundBeep
;~ SoundBeep, 600
stop := 0
dist := 1
MouseGetPos, cx, cy
lx := cx
ly := cy
Gui, t:+AlwaysOnTop -Caption +Border +LastFound +ToolWindow
WinSet, TransColor, f0f0f0
windows := []
count := 0
currentFinds:= 0
;~ While( !stop ){
While( GetKeyState( "g" , "p" ) ){
MouseGetPos, cx, cy
if( cx != lx || cy != ly ){
lx := cx
ly := cy
dist := 1
}
sx := cx - dist
ex := cx + dist
sy := cy - dist
ey := cy + dist
Gui, t:Show, % "x" sx " y" sy " w" ex - sx " h" ey - sy " NA"
PixelSearch, tx, ty, sx, sy, ex, ey, % color, % variation, RGB Fast
if( !ErrorLevel ){
++currentFinds
;********************
Action_Function_1( tx , ty , move ) ;<<<<<----- Call the function that contains the actions to perform if the color is found. Passing the found x and found y values.
;********************
dist := 1
Gui, New, +AlwaysOnTop -Caption -DPIScale +ToolWindow +hwndhwnd +E0x20
windows.Push( hwnd )
Gui, Color, 22262a
Gui, Show, % "x" tx - blockSize / 2 " y" ty - blockSize / 2 " w" blockSize " h" blockSize " NA"
Sleep, 30
if( tx < range / 2 && ty < range / 2 )
MouseMove, tx + range / 2 , ty + range / 2
else if( tx < range / 2 )
MouseMove, tx + range / 2 , ty
else if( ty < range / 2 )
MouseMove, tx, ty + range / 2
else if( tx > A_ScreenWidth - range / 2 && ty > A_ScreenHeight - range / 2 )
MouseMove, tx - range / 2 - 2, ty - range / 2 - 1
else if( tx > A_ScreenWidth - range / 2 )
MouseMove, tx - range / 2 - 2 , ty
else if( ty > A_ScreenHeight - range / 2 )
MouseMove, tx , ty - range / 2 - 2
if( stop )
break
if( ++count > maxblocks && count := maxblocks ){
Gui, % windows[ 1 ] ":Destroy"
windows.Remove( 1 )
}
if( currentFinds = maxFinds && maxFinds ){
break
}
sleep, 30
}
if( ( dist += rate ) > range )
dist := 1
if( !startTime ){
startTime := A_TickCount
}
if( StartTime && ( A_TickCount - Delay ) > StartTime ){
startTime := 0
if( windows.Length() ){
count--
Gui, % windows[ 1 ] ":Destroy"
windows.Remove( 1 )
}
}
}
;~ sleep, 500
for k , v in windows {
Gui, % windows[ k ] ":Destroy"
}
Gui, t:Destroy
KeyWait, g
return
;}
;********************
;********************
;********************
;When the color is found it runs this code.
Action_Function_1( x , y , move := 0 ){ ;<--- You can "pass" as many arguments as you need to. In this example I am just passing the x and y values for where the color was found.
;~ MouseMove, x, y ;example of moving the cursor.
;~ Sleep, 500
;********************
;This is the action you asked for.
send, { Space, Down } ;hold the space key down
sleep, 30 ;wait a fraction of a second
Send, % "{ Click , " x " , " y " }" ;send a click
sleep, 30 ;wait a fraction of a second
send, { Space, Up } ;release the space key.
sleep, 30 ;wait a fraction of a second
;********************
return 1
}
;********************