Console Autohotkey

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Alessandro
Posts: 5
Joined: 14 Feb 2018, 06:05

Console Autohotkey

14 Feb 2018, 06:19

Hi , I am Alessandro and I would to create a console log to print on screen any errors . How can I do this ? Is there any functions or library to include?
Guest

Re: Console Autohotkey

14 Feb 2018, 07:28

Yes that should be possible.

Depends on your definition of console. If you mean the dos command prompt/window you can have a look at these two libraries:
https://github.com/ahkscript/awesome-AutoHotkey#console
or use ConsoleSend() https://autohotkey.com/board/topic/25446-consolesend/

Otherwise you can just create a GUI with an edit control and "send" data to it. If you want to do "more" like displaying the contents of arrays and have pretty colours you can have a look at this "console"
https://github.com/AfterLemon/Class_Console and a fork https://github.com/hi5/Class_Console (adds: Escape <> HTML tags and colors for objects/arrays)

Here is a tutorial for writing cmd line apps https://autohotkey.com/boards/viewtopic.php?f=7&t=37722
User avatar
SL5
Posts: 879
Joined: 12 May 2015, 02:10
Contact:

Re: Console Autohotkey

14 Feb 2018, 08:53

i also like to print to console, or log file very much. but i also like to print som importand errors to the screen as massaage. i like to use this: https://github.com/sl5net/global-Intell ... c.ahk#L990
Alessandro
Posts: 5
Joined: 14 Feb 2018, 06:05

Re: Console Autohotkey

14 Feb 2018, 09:05

I want to include my script in a sequence of batch tests, so I must to record or to log the stdout of the execution of every batch
I see the solution from ConsoleSend() but I'm not been able to run it . Does anyone has a solutions that run on Windows terminal OS ?
Regards , Alessandro
garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: Console Autohotkey

14 Feb 2018, 17:22

( not sure what you want )
example from wolf_II
https://autohotkey.com/boards/viewtopic.php?t=43192
example : Listbox with attached DOS Window > send commands to DOS
; drag at Listbox to move both windows
; close Listbox > also closes DOS/close DOS also this script close

Code: Select all

;-modified = 20180214
;-created  = 20180211

;-------- https://autohotkey.com/boards/viewtopic.php?t=43192 -------------
;- script moveTogether()                               > from user= Wolf_II

;--------- LISTBOX send selected  commands to DOS --------------------------
;- example : Listbox with attached DOS Window > send commands to DOS
;            drag at Listbox to move both windows
;            close Listbox > also closes DOS/close DOS also this script close
;-------------------------------------------------------------------------------------

#warn
#NoEnv
setworkingdir,%a_scriptdir%
DetectHiddenWindows, ON
SetKeyDelay,20,20
sendmode,input


Handles := []
gosub,crea

;------------ ahk script Listbox --------------------
i=0
x1:=0
y1:=30
w1:=300
h1:=900
h2:=932

   ;- create ahk GUI = Listbox
   Gui,1: New, hwndhWin, Window 1
   Gui,1:default
   Gui,1:Color,Black
   Gui,1:Color,ControlColor, Black
   Gui,1:Font,s12 cYellow ,Lucida Console

   Menu,S1,add,FolderSelect          ,MH0
   menu,myMenuBar,Add,Change Directory   ,:S1
   Gui,1:menu,MyMenuBar

   Gui,1:add,Listbox,x%x1% y%y1% w%w1% h%h1% gLb1 vLbx cYellow,%lb%
   ;Gui,1:add,Button ,x10 y910 w100 h26 gTest,Test
   Gui,1:Show,       x%x1% y1 w%w1% h%h2%,Drag & Close here

   Handles.Push(hWin)

;----------- next-attached window > DOS ----------
x3:=(w1+5)
y3:=1
w3:=1220
h3:=(975)

;-- example-1 send to DOS
e4x=
(Ltrim Join&
cd\
dir
)
;Run, %COMSPEC% /k %e4x%,,,pid2       ;- start DOS and send different commands

;----------------------------
;- example-2
title2=AutoHotkey DOS
Run, %COMSPEC% /S /U /Q /E:ON /F:ON /T:0A /k "title %title2% & mode con lines=4048 cols=120&CD\&@echo off",,,pid2   ; define title / lines / colons / color
;----------------------------
WinWaitActive, ahk_pid %pid2%
sleep,200
WinMove, ahk_pid %pid2%, , x3, y3, w3, h3                     ;- move DOS to the right position
sleep,200
controlsend,,ver`n,ahk_pid %pid2%                             ;- send another command if needed

IfWinNotActive ,ahk_pid %pid2%,,WinActivate,ahk_pid %pid2%    ;- Activate DOS
  WinWaitActive,ahk_pid %pid2%
sleep,200
Handles.Push(WinExist("A"))                                   ;- DOS is lastactive
MoveTogether(Handles)
settimer,closethisscript,500                                  ;- close this script also if DOS was closed
Return
;-------------------------------------------------------------------------------------------------------------

MH0:
FileSelectFolder,dirc, , 3
If dirc =
  return
;ControlSend,%title1%,cd "%dirc%"`n,
controlsend,,cd "%dirc%"`n,ahk_pid %pid2%
IfWinNotActive ,ahk_pid %pid2%,,WinActivate,ahk_pid %pid2%
  WinWaitActive,ahk_pid %pid2%
return


closethisscript:
process, exist, %PID2%
 status1 = %ErrorLevel%
if (status1 = 0)          ;- close this ahk-script if PID2 ( DOS ) not exist
  exitapp
return

Guiclose:                                                      ;- when close Listbox-GUI close also attached DOS
WinClose, ahk_pid %pid2%                                       ;- if close only DOS , ahk-script freeze but you can close it
WinWaitClose,ahk_pid %pid2%
exitapp
;------------------------------------

Lb1:                                                           ;- send commands to DOS and let DOS active
Gui,1:submit,nohide
IfWinNotActive ,ahk_pid %pid2%,,WinActivate,ahk_pid %pid2%
  WinWaitActive,ahk_pid %pid2%
controlsend,,`n%lbx%`n,ahk_pid %pid2%                          ;- send command from Listbox to DOS
return
;==============================================================================


crea:
lb=
(ltrim join|
cd\
ver
dir
vol
cmd /?
help
date /t
time /t
cacls /?
title /?
type /?
md /?
move /?
graftabl /status
erase /?
comp /?
compact /?
chcp
path
ping /?
ping -n 4 -w 1000 www.google.com
netstat /?
netstat
netstat -an
netstat -e -s
ipconfig /?
ipconfig /all
logoff /?
shutdown /?
sfc /?
mem /?
copy /?
xcopy /?
mode /?
label /?
start /?
subst /?
verify /?
Format /?
fc /?
find /?
findstr /?
convert /?
color /?
at /?
attrib /?
charmap
notepad
calc
winver
)
sort,lb,D|
return


;-------------------------------------------------------------------------------
MoveTogether(wParam, lParam = "", _ = "", hWnd = "") { ; using DeferWindowPos
;-------------------------------------------------------------------------------
    ; call MoveTogether(Handles) with an array of handles
    ; to set up a bundle of AHK Gui's that move together
    ;---------------------------------------------------------------------------
    ; https://autohotkey.com/boards/viewtopic.php?p=199402#p199402
    ; version 2018.02.08

    static init := OnMessage(0xA1, "MoveTogether") ; WM_NCLBUTTONDOWN
    static Handles

	If IsObject(wParam)             ; detect a set up call
		Return, Handles := wParam   ; store the array of handles

    If (wParam != 2) ; HTCAPTION
        Return

    ; changing AHK settings here will have no side effects
    CoordMode, Mouse, Screen    ; for MouseGetPos
    SetBatchLines, -1           ; for onMessage
    SetWinDelay, -1             ; for WinActivate, WinMove

    M_old_X := lParam & 0xFFFF, M_old_Y := lParam >> 16 & 0xFFFF
    WinActivate, ahk_id %hWnd%

    Win := {}
    For each, Handle in Handles {
        WinGetPos, X, Y, W, H, ahk_id %Handle%
        Win[Handle] := {X: X, Y: Y, W: W, H: H}
    }

    While GetKeyState("LButton", "P") {
        MouseGetPos, M_new_X, M_new_Y
        dX := M_new_X - M_old_X, M_old_X := M_new_X
      , dY := M_new_Y - M_old_Y, M_old_Y := M_new_Y

        If GetKeyState("Shift", "P")
            WinMove, ahk_id %hWnd%,, Win[hWnd].X += dX, Win[hWnd].Y += dY

        Else { ; DeferWindowPos cycle
            hDWP := DllCall("BeginDeferWindowPos", "Int", Handles.Length(), "Ptr")
            For each, Handle in Handles
                hDWP := DllCall("DeferWindowPos", "Ptr", hDWP
                    , "Ptr", Handle, "Ptr", 0
                    , "Int", Win[Handle].X += dX
                    , "Int", Win[Handle].Y += dY
                    , "Int", Win[Handle].W
                    , "Int", Win[Handle].H
                    , "UInt", 0x214, "Ptr")
            DllCall("EndDeferWindowPos", "Ptr", hDWP)
        }
    }
}
;=================================== END script ====================================
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Console Autohotkey

15 Feb 2018, 04:53

There are some other ideas here, including a simple script by me.
AHK Console - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=37043
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
joedf
Posts: 8959
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Console Autohotkey

15 Feb 2018, 16:23

If you want to interact with the windows terminal itself
you may try https://github.com/joedf/LibCon.ahk
or these other alternatives too! :+1:
https://github.com/G33kDude/Console
https://github.com/NickMcCoy/AHK-Console-Class
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Joey5, lechat, sebalotek and 278 guests