如何为脚本设置区域? Sikuli

时间:2017-01-31 23:28:29

标签: python automation sikuli

我的问题是我不知道如何在特定区域运行我的代码 - 它会继续扫描整个屏幕。如果有人能看到它,这是我的伪劣代码。

running = True

def runHotkey(event):
global running
running = True

Env.addHotkey(Key.F1, KeyModifier.CTRL, runHotkey)
Settings.MoveMouseDelay = 0 
Region(Region(23,54,731,778))
while exists("1485901173411.png") and running: 

  click("1485900597943.png")    
  if exists(Pattern("1485900218788.png").similar(0.95)):
      type(Key.CTRL + "L")
      wait(1)
      type(Key.ALT + Key.ENTER)
      wait(10)
  else:
      click("1485901173411.png")
      wait(7)

1 个答案:

答案 0 :(得分:0)

正如您所说,为了限制搜索区域,您必须在预定义区域内查找模式。定义区域的方法很少。

使用坐标

例如,如果您只想查看屏幕的上半部分,则可以执行以下操作:

topHalfScreen = Region(x, y, w, h)

然后:

targetPattern = topHalfScreen.find("targetPattern.png")

此处您还可以使用getScreen().getBounds().widthgetScreen().getBounds().height来确定屏幕尺寸。

使用模式

几乎相同的想法,但不是定义屏幕区域,而是寻找包含您要查找的模式然后在其中搜索的模式。

使用相对模式

这样您就可以根据其他模式的位置搜索模式。例如:

initialPattern = find("pattern.png")
actualRegion = Region(initialPattern.x + x1, initialPattern.y + y1, initialPattern.w + w1, initialPattern.h + h1)