Please forgive my poor English. I use machine translation.
Hello everyone! Recently, I encountered the question of "Hide" parameter about the "run" command. Now I would like to ask you.
The problem is this: using the run command, running the ffmpeg command line program to record the screen, everything is OK.
However, I wanted to cancel the CMD window of ffmpeg, so I used the "hide" parameter of the "run" command.
The result is that the CMD window of ffmpeg is hidden, which is very good.
However, my command to end ffmpeg cannot be sent to ffmpeg program.
Ask for advice, how to do?
The first is a perfect script that doesn't use the "hide" parameter.
The second is that after using the "hide" parameter, you can record, but you cannot stop recording and end the ffmpeg script.
——————————————————————————————————————————————————
大家好!最近遇到关于“run”命令的“Hide”参数问题,现在想请教大家。
问题是这样的:使用run命令,运行ffmpeg命令行程序录制屏幕,一切都好。
但是,我想取消ffmpeg的cmd窗口,于是使用了“run”命令的“Hide”参数。
结果是ffmpeg的cmd窗口被隐藏了,这非常好。
但是,我下达的结束ffmpeg的命令却无法发送给ffmpeg程序了。
求教,怎么办?
第一个是没有使用“Hide”参数的完美脚本。
第二个是使用了“Hide”参数后,可以录制,但无法停止录制并结束ffmpeg的脚本。
——————————————————————————————————————————————————
第一个The first
!^a::
WinShow, ahk_pid %ffmpegPid%
ControlSend,, q{Enter}, ahk_pid %ffmpegPid% ;ffmpeg quit
; here you can hide or close the cmd window
Return
I added an {Enter} in case that needs to also be pressed, which sounds like it would. You may not even need to show the window first, but that can give you a visual confirmation that it worked.
!^a::
WinShow, ahk_pid %ffmpegPid%
ControlSend,, q{Enter}, ahk_pid %ffmpegPid% ;ffmpeg quit
; here you can hide or close the cmd window
Return
I added an {Enter} in case that needs to also be pressed, which sounds like it would. You may not even need to show the window first, but that can give you a visual confirmation that it worked.
The "winshow" command mentioned in your reply broadens my mind. I did the experiment. And I also try to use other commands and functions to operate the hidden process.
Including using "detect hidden windows, on" (with this command, the script can detect the hidden process, but cannot issue "Q" exit command to it. If this command is enabled, the send Q command will be invalid when the "hide" parameter is not applicable.
But I was frustrated to find that all of this was ineffective.
Thank you again for your kind help.
Here are some of the commands and functions I tested:
在您的回复中提到的“WinShow”命令开阔了我的思路。我进行了试验。并且我还试着用其它命令和函数操作隐藏的进程,包括使用“DetectHiddenWindows, On”(用这个命令,脚本可以探测到隐藏的进程,但是让然无法对其下达“Q”退出命令。并且启用这个命令,还导致不适用“hide”参数时候,发送q命令失效)。但是我沮丧的发现:所有这些都是无效的。
再次感谢您的热心帮助。
下面是我试验的一些命令和函数:
;DetectHiddenWindows, On
!^F12::
;WinShow, ahk_pid %ffmpegPid%
;ControlSend,, q{Enter}, ahk_pid %ffmpegPid% ;ffmpeg quit
; here you can hide or close the cmd window
IfWinExist ahk_pid %ffmpegPid%
ControlSend, ahk_parent, q ;ffmpeg quit
ffmpegPid_str := % "ahk_pid " . ffmpegPid
ffmpeg_Hwnd := WinExist(ffmpegPid_str)
;ffmpeg_Hwnd := WinExist(ahk_pid %ffmpegPid%)
If WinExist(ahk_pid %ffmpegPid%)
ControlSend, ahk_parent, q ;ffmpeg quit
ControlSend,, q{Enter}, ahk_pid %ffmpegPid%
WinShow, ahk_pid %ffmpegPid%
ControlSend, ahk_parent, q
ControlSend,, q{Enter}, ahk_pid %ffmpegPid%
WinActivate, ahk_id %ffmpeg_Hwnd%
ControlSend, ahk_parent, q
ControlSend,, q{Enter}, ahk_id %ffmpeg_Hwnd%
Return
If that is meant to be a complete script, then it can't work because you haven't created the window with !^z:: yet. Many of the lines in your code below require that to already have been executed so that the variable ffmpegPid gets defined. But there are also problems with most of the other lines in your code. See the comments in the code below for the reasons why:
;DetectHiddenWindows, On
!^F12::
;WinShow, ahk_pid %ffmpegPid% ; HAS "ffmpegPid" BEEN DEFINED YET?
;ControlSend,, q{Enter}, ahk_pid %ffmpegPid% ; HAS "ffmpegPid" BEEN DEFINED YET?
; here you can hide or close the cmd window
IfWinExist ahk_pid %ffmpegPid% ; HAS "ffmpegPid" BEEN DEFINED YET?
ControlSend, ahk_parent, q ; NEED TO INCLDUE THE "WinTitle" PARAMETER
ffmpegPid_str := % "ahk_pid " . ffmpegPid ; HAS "ffmpegPid" BEEN DEFINED YET?. ALSO, THERE IS NO NEED FOR "%" AFTER ":="
ffmpeg_Hwnd := WinExist(ffmpegPid_str) ; THIS LINE WILL ONLY WORK IF ABOVE LINE IS CORRECT
;ffmpeg_Hwnd := WinExist(ahk_pid %ffmpegPid%) ; SYNTAX IS WRONG. MUST BE: WinExist("ahk_pid" ffmpegPid)
If WinExist(ahk_pid %ffmpegPid%) ; SYNTAX IS WRONG. MUST BE: WinExist("ahk_pid" ffmpegPid)
{ ; THIS IS NECESSARY TO DEFINE BLOCK OF CODE AFTER THE "IF" STATEMENT
ControlSend, ahk_parent, q ; NEED TO INCLDUE THE "WinTitle" PARAMETER
ControlSend,, q{Enter}, ahk_pid %ffmpegPid% ; HAS "ffmpegPid" BEEN DEFINED YET?
WinShow, ahk_pid %ffmpegPid% ; HAS "ffmpegPid" BEEN DEFINED YET?
ControlSend, ahk_parent, q ; NEED TO INCLDUE THE "WinTitle" PARAMETER
ControlSend,, q{Enter}, ahk_pid %ffmpegPid% ; HAS "ffmpegPid" BEEN DEFINED YET?
WinActivate, ahk_id %ffmpeg_Hwnd% ; HAS "ffmpegp_HWND" BEEN SUCCESSFULLY DEFINED YET?
ControlSend, ahk_parent, q ; NEED TO INCLDUE THE "WinTitle" PARAMETER
ControlSend,, q{Enter}, ahk_id %ffmpeg_Hwnd% ; HAS "ffmpegp_HWND" BEEN SUCCESSFULLY DEFINED YET?
} ; THIS IS NECESSARY TO DEFINE BLOCK OF CODE AFTER THE "IF" STATEMENT
Return
What I showed wasn't a complete script on its own. It assumed that the window was created first with your other hotkey. Try running this script exactly as shown:
If that is meant to be a complete script, then it can't work because you haven't created the window with !^z:: yet. Many of the lines in your code below require that to already have been executed so that the variable ffmpegPid gets defined. But there are also problems with most of the other lines in your code. See the comments in the code below for the reasons why:
;DetectHiddenWindows, On
!^F12::
;WinShow, ahk_pid %ffmpegPid% ; HAS "ffmpegPid" BEEN DEFINED YET?
;ControlSend,, q{Enter}, ahk_pid %ffmpegPid% ; HAS "ffmpegPid" BEEN DEFINED YET?
; here you can hide or close the cmd window
IfWinExist ahk_pid %ffmpegPid% ; HAS "ffmpegPid" BEEN DEFINED YET?
ControlSend, ahk_parent, q ; NEED TO INCLDUE THE "WinTitle" PARAMETER
ffmpegPid_str := % "ahk_pid " . ffmpegPid ; HAS "ffmpegPid" BEEN DEFINED YET?. ALSO, THERE IS NO NEED FOR "%" AFTER ":="
ffmpeg_Hwnd := WinExist(ffmpegPid_str) ; THIS LINE WILL ONLY WORK IF ABOVE LINE IS CORRECT
;ffmpeg_Hwnd := WinExist(ahk_pid %ffmpegPid%) ; SYNTAX IS WRONG. MUST BE: WinExist("ahk_pid" ffmpegPid)
If WinExist(ahk_pid %ffmpegPid%) ; SYNTAX IS WRONG. MUST BE: WinExist("ahk_pid" ffmpegPid)
{ ; THIS IS NECESSARY TO DEFINE BLOCK OF CODE AFTER THE "IF" STATEMENT
ControlSend, ahk_parent, q ; NEED TO INCLDUE THE "WinTitle" PARAMETER
ControlSend,, q{Enter}, ahk_pid %ffmpegPid% ; HAS "ffmpegPid" BEEN DEFINED YET?
WinShow, ahk_pid %ffmpegPid% ; HAS "ffmpegPid" BEEN DEFINED YET?
ControlSend, ahk_parent, q ; NEED TO INCLDUE THE "WinTitle" PARAMETER
ControlSend,, q{Enter}, ahk_pid %ffmpegPid% ; HAS "ffmpegPid" BEEN DEFINED YET?
WinActivate, ahk_id %ffmpeg_Hwnd% ; HAS "ffmpegp_HWND" BEEN SUCCESSFULLY DEFINED YET?
ControlSend, ahk_parent, q ; NEED TO INCLDUE THE "WinTitle" PARAMETER
ControlSend,, q{Enter}, ahk_id %ffmpeg_Hwnd% ; HAS "ffmpegp_HWND" BEEN SUCCESSFULLY DEFINED YET?
} ; THIS IS NECESSARY TO DEFINE BLOCK OF CODE AFTER THE "IF" STATEMENT
Return
What I showed wasn't a complete script on its own. It assumed that the window was created first with your other hotkey. Try running this script exactly as shown:
camfile := "s:/temp/0000000/" . A_Now . ".MP4"
(Ltrim Join`s
ffmpeg
-f gdigrab
-framerate 30
-offset_x 1920
-offset_y 0
-video_size 900x1600
-i desktop
-f mp4 %camfile%
) , ,hide ,ffmpegPid
WinShow, ahk_pid %ffmpegPid%
Sleep, 3000 ; wait 3 seconds so you can see the window
ControlSend,, q{Enter}, ahk_pid %ffmpegPid% ; send q and Enter to the window
Return
Thank you so much! Your code does work. The reason why my code didn't work was also found. Compared with your code, I found that I later added parameters for recording audio. Delete a few lines of recorded audio parameters, the use of your code is perfect! Thanks again!!
太感谢了!您的代码确实是有效果的。我的代码不成功的原因也找到了。对比您的代码,发现是我后来增加了录制音频的参数。删掉几行录制音频参数后,使用您的代码就完美了!再次致以诚挚的谢意!!