AHKnow* wrote:
temporarily block user input just before the console program terminates
We normally don't know when it would terminate.
AHKnow* wrote:
pass the original clipboard data into a variable too, like say variable "X". Then your script uses the clipboard. You then copy the contents of variable "X", back to the clipboard.
This is exactly what I meant. It is the standard practice, omitted from the original post for clarity
Code:
!c::
Settimer GetIt, 30 ; the GetIt thread will get the buffer
RunWait %comspec% /k dir c:\,,,PID ; will be closed from GetIt
; at this point: console buffer -> ClipBoard
StringReplace Text,ClipBoard,`r`n%A_WorkingDir%>,,R ; remove last command prompt
ClipBoard = %ClipBoard0% ; <- Restore original
MsgBox %Text% ; put here the code to process Text
Return
GetIt:
WinGetTitle Title, ahk_pid %PID% ; get the changing window title
If Title <> %comspec% ; program name affixed while busy
Return ; keep trying until idle
Settimer GetIt, Off ; need not run any more
WinActivate ahk_pid %PID% ; go to our console window
ClipBoard0= %ClipBoardAll% ; <- save original
ClipBoard = ; empty ClibBoard to see data comming
Send !{Space}es{Enter} ; select all = used buffer, copy to clipboard
ClipWait 2 ; wait until clipboard is available, < 2s
WinClose ahk_pid %PID% ; close console window
Return
With this version the two applications involved jump to the foreground, and the user's work get interrupted. There is no need to block user input.