Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Access to Command Window Contents

$
0
0
I am accessing the contents of the command window by scripting the "select all" and "copy" functionality.  My method works **BUT** I want to elimate the mouse click altogether.  I understand there is a menu selection function but I do not know how I would use it in this context.  Is there a way to access the menu in the command window without using a mouse click.  Also is there a way to copy the contents from the window outside of what I am doing?

CAVEAT... I **cannot** use a method to pipe or communicate such as command the StdoutRead and StdinWrite.  The application I am driving as a subprocess does not support it, which is why I am interacting with the command window.  Here is code I have written that works.

both "copyCmdWindowWithKeyboard" and "copyCmdWindowWithMouse" work but I really need to eliminate the use of MouseClick.  I could use a better method if you have one for getting the text from the command window.

Anything ideas?


Thank you,


W.



#include <Clipboard.au3>

Func setScriptPrefs()
Opt('WinWaitDelay',500)
Opt('WinDetectHiddenText',1)
Opt('MouseCoordMode',0)
Opt("WinTitleMatchMode", 2) ; ABSOLUTELY NECESSARY FOR WINDOW TITLE MATCHING
Opt("SendKeyDelay",1)  ; Alters the length of the brief pause in between sent keystrokes
EndFunc

Func activateWind( $title )
   If ( BitAND( WinGetState( $title ), 8 ) ) Then ; window is active
   Return( True )
   Else
   WinActivate($title)    ;if the window (by title) is not active then make it the active window
   return(  WinWaitActive($title,"", 5) )   ; return the window handle (non-zero) if the window exists and is active
   EndIf
EndFunc

Func copyCmdWindowWithMouse( $title )
   Local $mouseBtn = "primary"   ; "left"... the primary mouse button may be swapped so use "primary" instead of left
   ;BlockInput(1) ; disable user keyboard and mouse input
   activateWind( $title )
   MouseClick($mouseBtn,13,14,1,0)
   MouseClick($mouseBtn,67,154,1,0)
   MouseClick($mouseBtn,201,201,1,0)
   sendToWindow($title, "{ENTER}")
   ;BlockInput(0) ;re-enable keyboard and mouse input
EndFunc

Func copyCmdWindowWithKeyboard( $title )
   Local $mouseBtn = "primary"   ; "left"... the primary mouse button may be swapped so use "primary" instead of left
   ;BlockInput(1) ; disable user keyboard and mouse input
   activateWind( $title )
   MouseClick($mouseBtn,10,12,1, 0)
   sendToWindow($title, "{DOWN 7}{RIGHT}{DOWN 3}{ENTER 2}") ;"{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{RIGHT}{DOWN}{DOWN}{DOWN}{ENTER}{ENTER}"
   ;BlockInput(0) ;re-enable keyboard and mouse input
EndFunc

Func sendToWindow( $title, $sendStr )
   If ( activateWind( $title ) ) Then
   Send( $sendStr )
   Sleep( 500 )  ; Let some time to pass (allowing for keystrokes to make it to the screen) before returning
   Return( True ) ; we sent string to the title window
   Else
   Return( False ) ; we were not able to send because the title window was not active
   EndIf
EndFunc

setScriptPrefs()

$title = "Capture CMD Info"
$sendStr = "This is a test of the emergency broadcast system.  This is only a test."

Run(@ComSpec & " /k TITLE "& $title, "c:\", @SW_MAXIMIZE)

sendToWindow( $title, $sendStr )
copyCmdWindowWithKeyboard( $title )
MsgBox(0, "Captured", _ClipBoard_GetData() & @LF)

Viewing all articles
Browse latest Browse all 12506

Trending Articles