Posts: 5
Threads: 1
Joined: Jun 2021
Hello, I'm new with QM and I will really appreciate a help for converting my Autohotkey macro to QM.
My goal is to do CTRL-S and if TC Windows is not active, show it, if TC Windows is active, hide to tray, in this way I can activate or hide TC pressing CTRL-S
Here is my Autohotkey script
PATH_COMMANDER := "C:\totalcmd\TOTALCMD64.EXE"
;--TOTALCOMMANDER
^!s::
Winget, NewPID, ID, ahk_class TTOTAL_CMD
F_HIDE_SHOW("TTOTAL_CMD",PATH_COMMANDER,"Total Commander","TTOTAL_CMD")
return
F_HIDE_SHOW(PRG,PATH,NAME,TRAY)
{
DetectHiddenWindows, On
Winget, WinID, PID, ahk_class %PRG%
DetectHiddenWindows, Off
if (WinID <> "")
{
{
If WinActive("ahk_class " . PRG) <> 0
{
WinGetTitle, TheWinTitle, ahk_class %PRG%
menu, tray, Tip, %NAME%
menu, tray, add, %NAME%, %TRAY%
WinHide, ahk_class %PRG%
return
}
else
{
menu, tray, UseErrorLevel
menu, tray, Delete, %NAME%
WinShow, ahk_class %PRG%
WinActivate, ahk_class %PRG%
}
}
}
else
{
Run %PATH%
WinActivate, ahk_class %PRG%
}
}
Thanks in advance!
Posts: 1,336
Threads: 61
Joined: Jul 2006
This should cover it
Function TotalCommanderHideShowWithTrayIcon
Trigger Cs
;On Keypress Ctrl+s adds tray icon and stays running. If Total Commander if not running runs and exits.
;Sub-function TrayProc is called on mouse events.
int w=win("Total Commander" "TTOTAL_CMD")
if(!w)
,run "C:\Program Files\totalcmd\TOTALCMD64.EXE";; change to location on your pc if not this
,ret
int h=hid(w)
if(!h)
,hid w
,Tray t.AddIcon("C:\Program Files\totalcmd\TOTALCMD64.EXE" "Show Total Commander" 0 &sub.TrayProc)
,MessageLoop
else
,EndThread +getopt(itemid)
,act w
,ret
#sub TrayProc v
function Tray&tray msg
sel msg
,case WM_LBUTTONUP
,sel GetMod
,,case 0 ;;left click on icon
,,act w
,,shutdown -7
,,case 2 ;;control +left click on icon
,,act w
,,shutdown -7
Posts: 5
Threads: 1
Joined: Jun 2021
Thanks Kevin for the function, is working but I think there is a little tweak to be made.
With TC not running, if I press CTRL-S TC windows is active, if I press again, TC goes to the tray, but If I press again CTRL-S, TC windows does not came active anymore, I need to click in the tray to make it active, what is the modification that should be done in your function to become active from the tray?
Posts: 1,336
Threads: 61
Joined: Jul 2006
06-20-2021, 02:10 AM
(This post was last modified: 06-20-2021, 02:38 AM by Kevin.)
i cant duplicate your results
you can try changing this
else
,EndThread +getopt(itemid)
,act w
,ret
to
else
,act w
,EndThread +getopt(itemid)
,ret
full code
Function Function342
;On Keypress Ctrl+s adds tray icon and stays running. If Total Commander if not running runs and exits.
;Sub-function TrayProc is called on mouse events.
int w=win("Total Commander" "TTOTAL_CMD")
if(!w)
,run "C:\Program Files\totalcmd\TOTALCMD64.EXE";; change to location on your pc if not this
,ret
int h=hid(w)
if(!h)
,hid w
,Tray t.AddIcon("C:\Program Files\totalcmd\TOTALCMD64.EXE" "Show Total Commander" 0 &sub.TrayProc)
,MessageLoop
else
,act w
,EndThread +getopt(itemid)
,ret
#sub TrayProc v
function Tray&tray msg
sel msg
,case WM_LBUTTONUP
,sel GetMod
,,case 0 ;;left click on icon
,,act w
,,shutdown -7
,,case 2 ;;control +left click on icon
,,act w
,,shutdown -7
Posts: 5
Threads: 1
Joined: Jun 2021
06-20-2021, 02:44 AM
(This post was last modified: 06-20-2021, 02:47 AM by citytrader.)
I did it before your message without success... I debugged the code and it remains in MessageLoop
Posts: 1,336
Threads: 61
Joined: Jul 2006
06-20-2021, 05:05 AM
(This post was last modified: 06-20-2021, 05:33 AM by Kevin.)
dont know still cant get reproduce it.
Try replacing MessageLoop with wait -1
Function TotalCommanderHideShowWithTrayIcon
Trigger Cs
;On Keypress Ctrl+s adds tray icon and stays running. If Total Commander if not running runs and exits.
;Sub-function TrayProc is called on mouse events.
int w=win("Total Commander" "TTOTAL_CMD")
if(!w)
,run "C:\Program Files\totalcmd\TOTALCMD64.EXE";; change to location on your pc if not this
,ret
int h=hid(w)
if(!h)
,hid w
,Tray t.AddIcon("C:\Program Files\totalcmd\TOTALCMD64.EXE" "Show Total Commander" 0 &sub.TrayProc)
,wait -1
else
,act w
,EndThread +getopt(itemid)
#sub TrayProc v
function Tray&tray msg
sel msg
,case WM_LBUTTONUP
,sel GetMod
,,case 0 ;;left click on icon
,,act w
,,shutdown -7
,,case 2 ;;control +left click on icon
,,act w
,,shutdown -7
Posts: 5
Threads: 1
Joined: Jun 2021
Still the same issue, this works perfectly but there is no icon in the tray
if(!h)
hid w
;Tray t.AddIcon("E:\D\totalcmd\TOTALCMD64.EXE" "Show Total Commander" 0 &sub.TrayProc)
;MessageLoop
;wait -1
ret
Posts: 1,336
Threads: 61
Joined: Jul 2006
06-20-2021, 07:24 PM
(This post was last modified: 06-20-2021, 08:09 PM by Kevin.)
ok I think I figured out the problem.
a couple things
#1 to post qm code in forum
In QM, to copy all or selected text, use menu Edit -> Other Formats -> Copy for QM Forum. It copies correct and colored code to the clipboard. Then simply paste in the forum. Don't use the Code button.
I cannot tell from your posted code what the formatting is
#2 to copy code from forum
click the copy link above the code and paste into qm
#3 Did you put the provided code into a Macro or a Function.
From what your saying is happening sounds like it was place in macro.
It should be a function. pressed (Ctrl+Shitf+N) to create a function and place code in there.
I am attaching below the code in qml format.
Just download and open and click either import(imports it into existing qm file-make sure you disable similar triggers or other macros ro function) or open(open as a new file) on qml file viewer window and run. and see if that works.
TotalCommanderHideShowWithTrayIcon.qml (Size: 3 KB / Downloads: 217)
Posts: 5
Threads: 1
Joined: Jun 2021
I just followed all the steps and it worked perfectly with the imported QML, thanks a lot for your time, what is the difference between doing it as a function compared with a macro?
|