Skip to content

脚本

PixPin 内嵌了一个基于 JavaScript 语法的简单脚本引擎,可以用来编写简单的脚本来使用 PixPin 的功能。

调用路径

快捷键/动作

可以通过在配置中的「快捷键/动作」页面设置脚本并通过快捷键或托盘菜单来调用。

启动命令(仅Windows支持)

通过在命令行中输入 pixpin.exe -r "脚本内容"pixpin.exe -f "脚本文件" 来执行脚本。

TIP

通过启动命令的方式执行脚本时,需要先启动一个PixPin的实例,脚本会在已经启动的实例中执行

预设脚本

在「快捷键/动作」中选择「脚本」后,可以从「预设」菜单快速填入以下脚本。

预设名称脚本
截图pixpin.screenShotAndEdit()
自定义/延时截图pixpin.openCustomScreenShot()
截图并复制pixpin.screenShot(ShotAction.Copy)
截图并贴图pixpin.screenShot(ShotAction.Pin)
截图并复制 OCRpixpin.screenShot(ShotAction.CopyOcrText)
截图并保存pixpin.screenShot(ShotAction.Save)
截图并快速保存pixpin.screenShot(ShotAction.QuickSave)
截图并长截图pixpin.screenShot(ShotAction.LongShot)
截图并 GIF 截图pixpin.screenShot(ShotAction.GifShot)
截图并翻译pixpin.screenShot(ShotAction.Translate)
截图并关闭pixpin.screenShot(ShotAction.Close)
截图并转表格pixpin.screenShot(ShotAction.OcrTable)
贴图pixpin.pinFromClipBoard()
从文件贴图pixpin.pinFromFiles(["path1", "path2"])
恢复上次关闭的贴图pixpin.restoreLastClosedPin()
关闭所有贴图窗口pixpin.closeAllPin()
隐藏/显示所有贴图窗口pixpin.hideOrShowAllPin()
开启/关闭鼠标穿透pixpin.trigMousePenetration()
禁用其他快捷键pixpin.disableShortcuts(!pixpin.isDisableShortcuts())
预设区域截图pixpin.screenShotAndEdit()
pixpin.setScreenShotRect(500, 500, 100, 100)
长截图shotRect = pixpin.genRectUnderCursor(640, 480)
pixpin.longScreenShot(shotRect)
GIF 截图shotRect = pixpin.genRectUnderCursor(640, 480)
pixpin.gifScreenShot(shotRect)
暂停 GIF 截图pixpin.gifShotPause()
切换贴图组pixpin.switchPinGroup()
执行系统命令(计算器)pixpin.runSystem("calc")
截取屏幕并复制pixpin.directScreenShotSpRect(PixConst.SpRectScreenUnderMouse, ShotAction.Copy)
截取活动窗口并复制pixpin.directScreenShotSpRect(PixConst.SpRectActiveWindow, ShotAction.Copy)
截取上次区域并复制shotRect = pixpin.getSpRect(PixConst.SpRectLastShotRect)
pixpin.directScreenShot(shotRect, ShotAction.Copy)
截取上次区域并保存到shotRect = pixpin.getSpRect(PixConst.SpRectLastShotRect)
pixpin.directScreenShotAndSaveTo(shotRect, "<DesktopPath>/PixPin_$yyyy-MM-dd_HH-mm-ss$.png")
贴图当前选中文件pixpin.pinSelectedFile()
切换鼠标下方窗口置顶pixpin.toggleWindowTopmostUnderMouse()
翻译剪贴板pixpin.translateClipboard()

<DesktopPath> 会在运行时替换为当前用户的桌面目录。

内置对象

pixpin

pixpin对象是PixPin的核心对象,提供了一些常用的功能


截图相关

  • pixpin.screenShotAndEdit()

    • 打开截图界面
  • pixpin.screenShot(AfterShotAction: ShotAction)

    • 打开截图界面,并设定用户选好截图区域后要执行的动作,支持的动作参考ShotAction的定义
    • 示例:pixpin.screenShot(ShotAction.Copy) 手动截图并复制
  • pixpin.directScreenShot(shotRect: rect, shotAction: ShotAction)

    • 直接截图(shotRect: 截图的区域,shotAction: 截图后的动作)
    • 示例:pixpin.directScreenShot(pixpin.genRect(100, 100, 500, 500), ShotAction.Copy) 截图100,100位置,宽高为500的区域并复制
  • pixpin.directScreenShotSpRect(type: int, shotAction: ShotAction)

    • 截取指定的特殊区域并执行截图后动作,支持的区域参考 PixConst 的定义
    • 示例:pixpin.directScreenShotSpRect(PixConst.SpRectActiveWindow, ShotAction.Copy) 截取活动窗口并复制
  • pixpin.directScreenShotAndSaveTo(shotRect: rect, path: string)

    • 直接截取指定区域并保存到指定路径
    • 路径支持日期时间占位符;<DesktopPath> 会在运行时替换为当前用户的桌面目录
    • 示例:pixpin.directScreenShotAndSaveTo(pixpin.getSpRect(PixConst.SpRectLastShotRect), "<DesktopPath>/PixPin_$yyyy-MM-dd_HH-mm-ss$.png")
  • pixpin.gifShotPause()

    • 暂停/继续GIF录制
    • 返回值 true:成功,false:失败(当前不是Gif录制的状态)
  • pixpin.setScreenShotRect(x: int, y: int, width: int, height: int)

    • 设置截图区域
    • 返回值 true:成功,false:失败(当前不在截图界面)
  • pixpin.setScreenShotRectRadius(ratio: number)

    • 设置截图区域的圆角
    • 返回值 true:成功,false:失败(当前不在截图界面)
  • pixpin.openCustomScreenShot()

    • 打开自定义截图界面
  • pixpin.longScreenShot(area: rect)

    • 打开长截图界面(area: 长截图的区域,可通过pixpin.genRect等返回rect类型的接口生成)
    • 示例:pixpin.longScreenShot(pixpin.genRect(100, 100, 500, 500)) 长截图100,100位置,宽高为500的区域
  • pixpin.openLongScreenShot(x: int, y: int, width: int, height: int)

    • 打开长截图界面(x, y, width, height: 长截图的区域)
  • pixpin.gifScreenShot(area: rect)

    • 打开GIF截图界面(area: GIF截图的区域,可通过pixpin.genRect等返回rect类型的接口生成)
    • 示例:pixpin.gifScreenShot(pixpin.genRect(100, 100, 500, 500)) GIF截图100,100位置,宽高为500的区域
  • pixpin.openGifScreenShot(x: int, y: int, width: int, height: int)

    • 打开GIF截图界面(x, y, width, height: GIF截图的区域)
  • pixpin.genRectUnderCursor(width: int, height: int)

    • 生成以鼠标位置为中心的矩形区域
    • 示例:pixpin.genRectUnderCursor(100, 100) 生成以鼠标位置为中心,宽高为100的矩形区域
  • pixpin.genRect(x: int, y: int, width: int, height: int)

    • 生成矩形区域
  • pixpin.getSpRect(type: int)

    • 获取特殊矩形区域
    • 参数值:
      • PixConst.SpRectScreenUnderMouse : 鼠标所在的屏幕区域
      • PixConst.SpRectAllScreen : 所有屏幕区域
      • PixConst.SpRectWindowUnderMouse : 鼠标所在的窗口区域
      • PixConst.SpRectLastShotRect : 最后一次截图的区域

贴图相关

  • pixpin.pinFromClipBoard()

    • 从剪贴板中获取数据贴图
  • pixpin.pinFromFiles(paths: string[])

    • 将一个或多个指定路径的文件贴到屏幕上
    • 示例:pixpin.pinFromFiles(["path1", "path2"])
  • pixpin.pinSelectedFile()

    • 将文件管理器中当前选中的文件贴到屏幕上
  • pixpin.destoryAllPin()

    • 销毁所有贴图
  • pixpin.saveAllPinImageTo(path: string)

    • 保存屏幕上所有贴图到指定路径
    • 路径可以包含中文
    • 示例:pixpin.saveAllPinImageTo("C:/Users/xxx/桌面/PixPin贴图") 保存到包含中文目录的路径
    • 注意在Windows下路径建议使用/来分隔;如果使用反斜杠,需要写成\\,例如C:\\Users\\xxx\\桌面\\PixPin贴图
  • pixpin.saveAllPinImageWithDialog()

    • 保存屏幕上所有贴图,弹出保存对话框来选择保存路径
  • pixpin.restoreLastClosedPin()

    • 恢复最后一次关闭的贴图
    • 返回值 true:成功,false:失败
  • pixpin.trigMousePenetration()

    • 设置/取消鼠标所在位置的贴图的鼠标穿透
  • pixpin.closeAllPin()

    • 关闭所有贴图
  • pixpin.setAllPinToRoiMode()

    • 设置所有贴图为缩略图模式
  • pixpin.unsetAllPinToRoiMode()

    • 取消设置所有贴图为缩略图模式
  • pixpin.hideOrShowAllPin()

    • 隐藏/显示所有贴图
  • pixpin.isAllPinHide()

    • 返回值 true:所有贴图都是隐藏状态,false:有贴图是显示状态
  • pixpin.openConfigurationWindow()

    • 打开配置窗口

其他

  • pixpin.switchPinGroup()

    • 打开切换贴图组的窗口
  • pixpin.disableShortcuts(checked: bool)

    • 禁用快捷键(checked: true 禁用,false 启用)
  • pixpin.isDisableShortcuts()

    • 返回值 true:快捷键被禁用,false:快捷键未被禁用
  • pixpin.runSystem(cmd: string)

    • 执行系统命令
    • 示例:pixpin.runSystem("calc") 打开计算器
  • pixpin.runSystemSync(cmd: string)

    • 执行系统命令并等待执行完毕返回结果

    • 示例:pixpin.runSystemSync("calc") 打开计算器

    • 返回值:

      json
      {
          "code" : 执行命令返回值,
          "output" : 命令正常输出,
          "error" : 命令错误输出,
      }
      {
          "code" : 执行命令返回值,
          "output" : 命令正常输出,
          "error" : 命令错误输出,
      }
  • pixpin.toggleWindowTopmostUnderMouse()

    • 切换鼠标下方窗口的置顶状态
  • pixpin.translateClipboard()

    • 翻译剪贴板中的文本

PixConst

定义可供截图接口使用的特殊区域。

  • PixConst.SpRectScreenUnderMouse

    • 鼠标所在的屏幕区域
  • PixConst.SpRectAllScreen

    • 所有屏幕区域
  • PixConst.SpRectWindowUnderMouse

    • 鼠标所在的窗口区域
  • PixConst.SpRectActiveWindow

    • 当前活动窗口区域
  • PixConst.SpRectLastShotRect

    • 上一次截图的区域

ShotAction

定义截图后的动作

  • ShotAction.Copy

    • 复制截图到剪贴板
  • ShotAction.Pin

    • 贴图
  • ShotAction.LongShot

    • 长截图
  • ShotAction.GifShot

    • GIF截图
  • ShotAction.CopyOcrText

    • 复制截图中的文字到剪贴板
  • ShotAction.Save

    • 保存截图
  • ShotAction.QuickSave

    • 快速保存截图
  • ShotAction.Translate

    • 翻译截图中的文字(需设置翻译的API Key或会员可用)
  • ShotAction.Close

    • 关闭截图
  • ShotAction.OcrTable

    • 截图中的文字转表格(会员可用)