 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
iNeed Help Guest
|
Posted: Sat Oct 31, 2009 3:44 pm Post subject: Grab text from console |
|
|
Hi,
i want to grab all the text from my CMD.exe console, i tried wingettext but it displayed nothing. What else can i do to grab text from cmd?
thanks |
|
| Back to top |
|
 |
n-l-i-d Guest
|
|
| Back to top |
|
 |
iNeed Help Guest
|
Posted: Sat Oct 31, 2009 4:30 pm Post subject: |
|
|
Hey thanks i got it now but another problem occur. I successfully grab all the text and wrote it to an .ini file. I check and its all there.
| Code: | | iniwrite, %Text%, cmd.ini, section1, key1 |
The text are all there, but when i tried to search for a particular word "Control" which is in the text, i can't get it. Any help?
| Code: | iniread, Textfound, cmd.ini, section1, key1
IfInString, Control, %Textfound%
{
MsgBox, The string was found.
return
}
else
Sleep, 1
return |
|
|
| Back to top |
|
 |
n-l-i-d Guest
|
Posted: Sat Oct 31, 2009 4:40 pm Post subject: |
|
|
| Code: | iniread, Textfound, cmd.ini, section1, key1
IfInString, Textfound, Control
{
MsgBox, The string was found.
return
}
else
Sleep, 1
return |
You swapped the order IfInString expects
| Quote: | IfInString, var, SearchString
|
HTH |
|
| Back to top |
|
 |
iNeed Help Guest
|
Posted: Sat Oct 31, 2009 5:25 pm Post subject: |
|
|
Argh, sorry i just found out that it only work for one time like a hotkey, if you put it on a timer, it will return AttachConsole failed - error 5. It wont run for more than once?
| Code: |
f1::
settimer, attach, on
return
Attach:
WinGet, pid, PID, ahk_class ConsoleWindowClass
; AttachConsole accepts a process ID.
if !DllCall("AttachConsole","uint",pid)
{
MsgBox AttachConsole failed - error %A_LastError%.
ExitApp
}
; If it succeeded, console functions now operate on the target console window.
; Use CreateFile to retrieve a handle to the active console screen buffer.
hConOut:=DllCall("CreateFile","str","CONOUT$","uint",0xC0000000
,"uint",7,"uint",0,"uint",3,"uint",0,"uint",0)
if hConOut = -1 ; INVALID_HANDLE_VALUE
{
MsgBox CreateFile failed - error %A_LastError%.
ExitApp
}
; Allocate memory for a CONSOLE_SCREEN_BUFFER_INFO structure.
VarSetCapacity(info, 24, 0)
; Get info about the active console screen buffer.
if !DllCall("GetConsoleScreenBufferInfo","uint",hConOut,"uint",&info)
{
MsgBox GetConsoleScreenBufferInfo failed - error %A_LastError%.
ExitApp
}
; Determine which section of the buffer is on display.
ConWinLeft := NumGet(info, 10, "Short") ; info.srWindow.Left
ConWinTop := NumGet(info, 12, "Short") ; info.srWindow.Top
ConWinRight := NumGet(info, 14, "Short") ; info.srWindow.Right
ConWinBottom := NumGet(info, 16, "Short") ; info.srWindow.Bottom
ConWinWidth := ConWinRight-ConWinLeft+1
ConWinHeight := ConWinBottom-ConWinTop+1
; Allocate memory to read into.
VarSetCapacity(text, ConWinWidth*ConWinHeight, 0)
; Read text.
if !DllCall("ReadConsoleOutputCharacter","uint",hConOut,"str",text
,"uint",ConWinWidth*ConWinHeight,"uint",0,"uint*",numCharsRead)
{
MsgBox ReadConsoleOutputCharacter failed - error %A_LastError%.
ExitApp
}
/* Alternate, slower method:
; Allocate memory to read into.
VarSetCapacity(buf, ConWinWidth*ConWinHeight*4, 0)
; Read an array of CHAR_INFO structures, containing text and attributes.
; Note: &info+10 is the address of a SMALL_RECT containing the coords we
; wish to read from. On success, it will receive the actual coords used.
if !DllCall("ReadConsoleOutput","uint",hConOut,"uint",&buf
,"uint",ConWinWidth|ConWinHeight<<16,"uint",0
,"uint",&info+10)
{
MsgBox ReadConsoleOutput failed - error %A_LastError%.
ExitApp
}
; buf should now contain an array of CHAR_INFO structures.
; We must decode this to retrieve readable text.
VarSetCapacity(text, ConWinWidth*ConWinHeight)
Loop % ConWinWidth*ConWinHeight
text .= Chr(NumGet(buf, 4*(A_Index-1), "Char"))
*/
; Optional: insert line breaks every %ConWinWidth% characters.
text := RegExReplace(text, "`a).{" ConWinWidth "}(?=.)", "$0`n")
; Finally, display the text.
MsgBox % text
return
| [/quote] |
|
| Back to top |
|
 |
n-l-i-d Guest
|
|
| Back to top |
|
 |
pajenn
Joined: 07 Feb 2009 Posts: 384
|
Posted: Sat Oct 31, 2009 8:41 pm Post subject: |
|
|
I use Skesoft's Text Capture Library together with the following script to capture text to clipboard from the command prompt window as well as from various other controls and windows:
| Code: | ;Requires Sean's COM Standard Library: http://www.autohotkey.com/forum/topic22923.html
;Requires Skesoft's Text Capture Library: http://www.skesoft.com/
;Hotkey: Win+T
;Action: Copies text to clipboard from window under mouse cursor
#t::
COM_Init()
tcServer := COM_CreateObject("TextCaptureLib.TextCapture")
tcWindow := COM_CreateObject("TextCaptureLib.Window")
COM_Invoke(tcWindow,"WindowFromCurrentPos")
;Clipboard := COM_Invoke(tcServer, "GetText", "+" tcWindow)
;RegEx below removes empty spaces\lines at the end
Clipboard := RegExReplace(COM_Invoke(tcServer, "GetText", "+" tcWindow),"[\s\n\r]+$")
COM_Release(tcServer)
COM_Release(tcWindow)
COM_Term()
Return |
Skesoft's Text Capture Library has a 30-day trial period _________________ Hardware: 1.8 GHz laptop with 4 GB ram, Windows XP/SP3
Software: Prevx, Privatefirewall, KeyScrambler. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|