Colors 自动热键:仅当按下该键时才搜索像素
我有一个简单的颜色点击代码Colors 自动热键:仅当按下该键时才搜索像素,colors,autohotkey,Colors,Autohotkey,我有一个简单的颜色点击代码 ~C:: Loop { PixelSearch, Px, Py, 300, 300, 300, 300, 0x91595c, 5, Fast if errorlevel { sleep 20 return } else { Send, {LButton Down} Sleep, 250
~C::
Loop
{
PixelSearch, Px, Py, 300, 300, 300, 300, 0x91595c, 5, Fast
if errorlevel
{
sleep 20
return
}
else
{
Send, {LButton Down}
Sleep, 250
Send, {LButton Up}
Sleep, 500
}
}
return
按C键时,它会找到正确的颜色并发送一个单击。
但我已经厌倦了让它只在按下C键时工作,而在不按下C键时完成颜色搜索
你已经尝试过什么?
我试图通过以下方式实现这一目标:
while KeyIsDown := GetKeyState("c", "P")
或
但它只是进入无限循环或者不起作用。
你有什么想法吗?找到解决方案:
$F2::
Loop
{
PixelSearch, Px, Py, 300, 300, 300, 300, 0x91595c, 5, Fast
if errorlevel
{
sleep 20
return
}
else
if GetKeyState("C","p")
{
Send, {LButton Down}
Sleep, 250
Send, {LButton Up}
Sleep, 500
}
}
return
很高兴看到您是否有更好的解决方案。如果我理解正确,您希望继续循环,直到您发布C。如果是这样,您不应该
在循环中返回,因为这样会停止循环
$F2::
Loop
{
PixelSearch, Px, Py, 300, 300, 300, 300, 0x91595c, 5, Fast
if errorlevel
{
sleep 20
}
else
if GetKeyState("C","p")
{
Send, {LButton Down}
Sleep, 250
Send, {LButton Up}
Sleep, 500
}
else
break ; C was released: exit the loop, thus exit the thread
}
return
此外,您可以将~C
作为热键,如果您真的只想“单击”,则不需要复杂的{LButton down}
等
建议的代码(也更紧凑):
$F2::
Loop
{
PixelSearch, Px, Py, 300, 300, 300, 300, 0x91595c, 5, Fast
if errorlevel
{
sleep 20
}
else
if GetKeyState("C","p")
{
Send, {LButton Down}
Sleep, 250
Send, {LButton Up}
Sleep, 500
}
else
break ; C was released: exit the loop, thus exit the thread
}
return
~c::
while(getKeyState("C","P)) {
PixelSearch, Px, Py, 300, 300, 300, 300, 0x91595c, 5, Fast
if( ! errorLevel ) {
click
sleep, 750
} else {
sleep 20
}
}
return