在没有推送的情况下使用特定程序中的热键

时间:2017-05-26 12:36:58

标签: batch-file

我想使用批处理文件打开一个软件即OBS(开放广播软件),然后自动开始录制而不受干扰。我为录制设置的热键是pgup,但我不想按它,我希望批处理文件自动发送按下pgup键并开始录制的信号。如何使用批处理文件执行此操作?

这是我用来启动它的代码。

@ECHO OFF
start /d "D:\OBS Studio\obs-studio\bin\64bit" obs64.exe

感谢。

1 个答案:

答案 0 :(得分:2)

如果您可以使用Run直接从AHK内部启动它,为什么要通过cmd传递它?

; Checks to see if you're running the script as admin
if not A_IsAdmin
{
   Run *RunAs "%A_ScriptFullPath%"  ; Requires v1.0.92.01+
   ExitApp
}

; The key you use to start/stop recording
startRec    := "PGUP"

; Path to your OBS exe
obsPath := "C:\Program Files (x86)\obs-studio\bin\64bit\obs64.exe"
; Splits path up int dir and file name.
SplitPath, obsPath, obsFileName, obsDir

; Closes any previously opened OBS instances
while WinExist("ahk_exe " obsFileName)
    WinClose, % "ahk_exe " obsFileName

; Run OBS
Run, % obsPath, % obsDir

; Waits until the OBS window has come up
while !WinExist("ahk_exe " obsFileName)
    Sleep, 1000

; Minimized OBS
WinMinimize, % "ahk_exe " obsFileName
Sleep, 1000

; Sends key to program to start recording
ControlSend, % "Qt5QWindowIcon2", {%startRec%}, % "ahk_exe " obsFileName

; Run your game here.

ExitApp