【问题标题】:AutoHotKey: PixelSearch only when key is pressedAutoHotKey:仅在按下键时进行像素搜索
【发布时间】:2016-03-15 03:28:58
【问题描述】:

我有一个简单的颜色点击器代码。

    ~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")

if  KeyIsDown := GetKeyState("c")

但它只是进入无限循环或不起作用。 你有什么想法吗?

【问题讨论】:

    标签: colors autohotkey


    【解决方案1】:

    寻找解决方案:

     $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
    

    很高兴看到您是否有更好的解决方案。

    【讨论】:

      【解决方案2】:

      如果我没听错的话,你希望保持循环直到你释放 C。如果是这样,你不应该在循环内return,因为那样会阻止它。

      $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}等。

      建议的代码(也更紧凑):

      ~c::
          while(getKeyState("C","P)) {
              PixelSearch, Px, Py, 300, 300, 300, 300, 0x91595c, 5, Fast
              if( ! errorLevel ) {
                  click
                  sleep, 750
              } else {
                  sleep 20
              }
          }
      return
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-03-20
        • 2013-06-07
        • 2021-05-25
        • 1970-01-01
        • 1970-01-01
        • 2013-11-21
        • 1970-01-01
        相关资源
        最近更新 更多