自动热键输入";powercfg电池报告”;在CMD中

自动热键输入";powercfg电池报告”;在CMD中,cmd,autohotkey,Cmd,Autohotkey,这可能是一件棘手的事情 我想使用Ctrl+b自动打开CMD并键入“powercfg batteryreport”,然后应该持续4秒钟。这样我就可以看到我的笔记本电脑电池使用情况 ; Ctrl + b ^b:: ; The %ComSpec% command starts a new instance of the command interpreter (CMD.exe) ; /k means: keep (do not close) this session after

这可能是一件棘手的事情

我想使用Ctrl+b自动打开CMD并键入“powercfg batteryreport”,然后应该持续4秒钟。这样我就可以看到我的笔记本电脑电池使用情况

; Ctrl + b
^b::    
    ; The %ComSpec% command starts a new instance of the command interpreter (CMD.exe)
    ; /k means: keep (do not close) this session after execution. The console window will remain open, even if the task has been finished already.
    Run, %ComSpec% /k powercfg batteryreport
    ; ahk_exe is used to identify a window belonging to the process with the given name
    WinWait, ahk_exe cmd.exe ; wait until the specified window exists
    Sleep, 4000 ; wait 4 seconds
    ; ControlSend sends simulated keystrokes to a window or control 
    ControlSend,, exit{Enter}, ahk_exe cmd.exe ; close cmd window
    ; open the output file (Win7):
    Run %A_WinDir%\system32\battery-report.html
return

有关更多详细信息,请参阅文档中的。

您可以尝试:
运行,%comspec%/k powercfg/batterreport,max
我在Mac上,无法在本地对其进行测试。虽然这可能回答了作者的问题,但它缺少一些解释文字和/或文档链接。如果没有一些短语,原始代码片段就没有多大帮助。你也会发现这很有帮助。请编辑你的答案-你能让我的任务完成时窗口关闭吗?等待4秒钟后,应键入另一个命令以打开输出文件,即由“Run,%ComSpec%/k powercfg batteryreport”创建的文件。文件名为battery-report.html,之后cmd窗口关闭