【问题标题】:Printscreen keystroke script . ^{PRTSC} not doing anythingPrintscreen 击键脚本。 ^{PRTSC} 什么都不做
【发布时间】:2021-03-07 12:30:27
【问题描述】:

我正在尝试创建一个批处理脚本,它将屏幕截图放在剪贴板上,以便我保存在另一个应用程序中。

我正在使用“^{PRTSC}”并从此处的另一个帖子中复制代码(我会在那里提问/评论,但列表已关闭,我没有足够的积分可以在那里发布。)

当我运行以下行时,我没有收到任何错误:

powershell -c "$wshell = New-Object -ComObject wscript.shell; $wshell.SendKeys("%{PRTSC}")

但是当我在 Photoshop 中创建一个新文档并选择粘贴 ctrl+v 时,剪贴板中没有粘贴任何内容。

显然代码没有在剪贴板中放置屏幕截图。

(我不想使用 Navcmd )

【问题讨论】:

  • 为什么要使用批处理?只需直接使用 PowerShell。有很多预建的,sample/example scripts all over the web for your use case。 MS powershellgallery.com 中甚至还有此类模块。例如搜索 Find-Module -Name 'capture'。您可以从批处理文件调用 PowerShell 脚本。最后,这样做会捕获您从中运行的控制台窗口,除非您通过快捷方式将其最小化或隐藏,并且您必须在双击后立即选择目标窗口。
  • 或者更确切地说是做这个复制/prtsc 的事情,我敢打赌 PhotoShop 是一个对象模块,它可以让您进一步自动化从屏幕上捕获内容并通过脚本将其插入到当前的 PhotoShop 窗口中。再一次,我从来没有出于任何原因需要 PhotoShop。所以,没有自动化它的经验。
  • 文档说你不能发送 prtsc。

标签: powershell batch-file keystroke printscreen


【解决方案1】:

这是一个旧的批处理脚本,它使用VB.net 中的一个模块并将屏幕截图保存为jpeg 带有系统日期的图像:


/*
@echo off & cls & color FC
Mode 30,3
::Autor Delmar Grande
::http://bbat.forumeiro.com/t248-bat-exe-printscreen-usando-vb-net
::Data  Qui 11 Jul 2013
:: Modified by Hackoo on 09/09/2016 to save image with system date
Title PrintScreen by Delmar Grande and modified by Hackoo
Rem Just adding a little timeout to organise our screenshot
Timeout /T 4 /Nobreak>nul
findstr "'%skip%VB" "%~f0">"%tmp%\%~n0.vb"
for /F %%i in ('dir /B /S ^"%WinDir%\Microsoft.NET\Framework\vbc.exe^"') do set "vbc=%%i"
if /i "%vbc%"=="" cls & color 1c & echo This script needs the framework & pause & Exit
cls
%vbc% /nologo /out:"%tmp%\%~n0.exe" "%tmp%\%~n0.vb"
"%tmp%\%~n0.exe"
del "%tmp%\%~n0.vb" >NUL 2>&1
del "%tmp%\%~n0.exe" >NUL 2>&1
exit
*/
Imports System.Windows.Forms 'VB
Module ModulePrintscreen 'VB
  Sub Main() 'VB
  Dim MaDate As String 'VB
  SendKeys.SendWait("{%}({PRTSC})") 'VB
  If My.Computer.Clipboard.ContainsImage() Then 'VB
  MaDate = Format(Now,"dd-MM-yyyy_hh-mm-ss") 'VB
  My.Computer.Clipboard.GetImage.Save(MaDate & ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg) 'VB
  End If 'VB
  End Sub 'VB
End Module 'VB

【讨论】:

    【解决方案2】:

    据我所知,windows键盘支持两种截屏快捷键:

    • PrtScn 捕获整个桌面
    • Alt+PrtScn 捕获活动窗口。

    根据标题和您的描述,^{PRTSC} 应该就像按下 Ctrl+PrtScn 一样,这将执行与 PrtScn 相同的操作kbd>.

    假设您只想捕获活动窗口,从批处理文件运行以下命令将起作用:

    powershell -c "Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.SendKeys]::SendWait('%%{PRTSC}')"
    

    有一些区别:

    • 使用 .NET 中的 SendWait 实现。 COM SendKeys 实现存在一些问题,特别是它对控制台窗口和特殊键的反应。
    • 我使用单引号来引用命令中的字符串,否则双引号将结束被引用的字符串被发送到 PowerShell。
    • 使用% 模拟Alt 键等,因为它在批处理文件中,将% 转义为%%

    【讨论】:

    • 在较新的 Windows 10 中还有 Win+PrintScreen 可以将屏幕截图直接保存为 *.png
    猜你喜欢
    • 2021-09-06
    • 2018-10-09
    • 2023-01-30
    • 1970-01-01
    • 1970-01-01
    • 2018-05-25
    • 2014-08-28
    • 1970-01-01
    • 2012-08-27
    相关资源
    最近更新 更多