AutoHotkey检测PixelColor的时间超过x秒

时间:2013-03-31 00:19:31

标签: global-variables global autohotkey

我的版本为AHL_L 32Bit 1.1.05.06

我正在寻找一种合理的方法来检测AutoHotkey,如果一个像素达到x时间,15秒后,我假设它崩溃了,我们将要刷新。

我目前的代码是这样的:

CrashCheck:
if stuckinbonus = 0x1D001A
{

    if(FoundCrash = 0) {   
     FirstFound := A_Tickcount
     FoundCrash = 1
        } else {
 CrashCheckTime := A_Tickcount - FirstFound
    }




if(CrashCheckTime >= 15000){
SetTimer,CrashCheck,off
 MsgBox,Refreshing page (Pseudo Code)
}
}
return

我已经尝试在脚本开头将这些变量设置为全局变量,但是我遇到的问题是CrashCheckTime只是0:/任何想法?

Global FoundCrash := ""
Global FirstFound := "0"
Global CrashCheckTime:= ""

2 个答案:

答案 0 :(得分:0)

这会完成这项工作吗?

#SingleInstance Force
#installKeybdHook
#Persistent
SetTimer, CrashCheck, 1000 ; run CrashCheck every second
MyAlert := 0
Return

CrashCheck:
PixelGetColor, Color, 100, 100
If (Color = 0x1D001A)
{
    MyAlert++
}
Else
{
    MyAlert := 0
}
If (MyAlert > 15)
{
    MyAlert := 0
    Refresh Page
}
Return

关于你自己的代码。可能是你在运行CrashCheck之前没有设置FoundCrash := 0吗?这样你就永远不会对If (FoundCrash = 0)成为现实,因此总是跳到Else选择。

示例:

#SingleInstance Force
#installKeybdHook
#Persistent
;FoundCrash := 0 ; Script fails when this line is commented out!
stuckinbonus = 0x1D001A

!t:: ; [Alt]+t to simulate CrashCheck
If (stuckinbonus = 0x1D001A)
{
    If (FoundCrash = 0)
    {   
        SoundBeep, 500, 500 ;(Low beep)
                FirstFound := A_Tickcount
        FoundCrash := 1
    }
    Else
    {
        SoundBeep, 1500, 500 ;(High beep)
        CrashCheckTime := A_Tickcount - FirstFound
    }
    If (CrashCheckTime >= 15000)
    {
    ;SetTimer,CrashCheck,off
    FoundCrash := 0
    MsgBox,Refreshing page (Pseudo Code)
    }
}
Return

我建议你在SciTE4AutoHotKey中的调试模式下运行它,以查看在逐步执行期间采取了哪些分支以及变量值是什么。

答案 1 :(得分:0)

我写了一个小函数,它循环,等待并保持循环,直到它在所需的坐标处看到所需的像素颜色。也许这有用吗?

;This function checks the Pixel at the provided coordinates and waits until the colour matches the provided parameter 
WaitForLoad(PixelColorX,PixelColorY,PixelColorValue)
{
CycleCount = 0
  PixelGetColor SearchPixel, PixelColorX, PixelColorY
  ;msgbox "Found Pixel %SearchPixel% at %PixelColorX%, %PixelColorY%, Looking for %PixelColorValue%" ;DEBUGG ASSISTANT
  While (SearchPixel != PixelColorValue)
          {
    CycleCount = CycleCount + 1
    sleep 100
    ; Tooltip Waiting to detect pixels HERE!, PixelColorX, PixelColorY     ; Doesn't work
    PixelGetColor SearchPixel, PixelColorX, PixelColorY
  }
  sleep 500
;Debug
;msgbox Exiting Function with %PixelColorValue% at %PixelColorX%, %PixelColorY% after %CycleCount% Cycles.
SearchPixel = 0
PixelColorValue = 1