简体   繁体   English

使用 Sikuli 自动截取窗口的屏幕截图?

[英]Using Sikuli to take automated screenshots of a window?

Simple question here: I'd like to use Sikuli to take a screenshot of a window on a mac, which would be done by hitting CMD+SHIFT+4 then hitting Space, then clicking a window.这里有一个简单的问题:我想使用 Sikuli 在 Mac 上截取一个窗口的屏幕截图,这可以通过点击 CMD+SHIFT+4 然后点击 Space,然后点击一个窗口来完成。

For the CMD+SHIFT+4 I'm having trouble.对于 CMD+SHIFT+4 我遇到了麻烦。 This doesn't work:这不起作用:

keyDown(KEY_META)
keyDown(Key.SHIFT)
wait(1)
type("4")
wait(1)
keyUp(Key.SHIFT)
keyUp(KEY_META)

Anyone have any ideas?谁有想法? I'm open to other routes of hitting the key combo, for instance, I know to copy this works well:我对其他击键组合的路线持开放态度,例如,我知道复制这个效果很好:

type("c",KEY_META)

But, it doesn't accept three arguments.但是,它不接受三个参数。

type("4", KeyModifier.CMD+KeyModifier.SHIFT)

Or, even better:或者,甚至更好:

import shutil
import os
screenshotsDir = "absolute-path-to-a-folder"
img = capture(some_region)
shutil.move(img, os.path.join(screenshotsDir, "some-name.png"))

where some_region is: some_region 在哪里:

some_region = SCREEN # for whole screen

or要么

someRegion = App.focusedWindow() # for the frontmost window

This has the advantage, that you can control the file name of the shot.这样做的好处是,您可以控制镜头的文件名。

Have found a better solution, which actually works:找到了一个更好的解决方案,它实际上有效:

screen = Screen()
scr_img = screen.capture(screen.getBounds())
scr_img.save("C:\Screenshots", "screenshot")

Screen.capture() returns an instance of ScreenImage class with methods:'save', 'saveInBundle', 'getFile', 'getFilename'. Screen.capture() 使用以下方法返回 ScreenImage 类的实例:'save'、'saveInBundle'、'getFile'、'getFilename'。 The method save() adds an unique number to a supplied prefix parameter.方法 save() 向提供的前缀参数添加一个唯一编号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM