Feature Request: Run macro w/o bringing XY to foreground

Features wanted...
MBaas
Posts: 654
Joined: 15 Feb 2016 21:08

Feature Request: Run macro w/o bringing XY to foreground

Post by MBaas »

I have set up some system-wide hotkeys (using LibreAutomate) that send WM_COPYDATA ::run commands to XY to execute macros (which bring up popupmenus).
This all works nice, smooth & fast :appl:

The only wish I have regarding the flow is: when receiving my msg, XY comes to foreground. I see that this is neccessary in most cases, but here it would be much nicer if XY stayed in the background and only showed the popupmenu in foreground. Clearly this is non-default behavior and I'd be happy to set flags in my macros or possibly include specific instructions (or flags) in the send command.
_________________________________________________
Happy user with Screen scaling 100% and W11Pro 24H2 ;-)

jupe
Posts: 3296
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Feature Request: Run macro w/o bringing XY to foreground

Post by jupe »

I am not sure of your exact scenario regarding what you describe as sending run cmds etc, but just FYI you can already use popupmenus via wmcopydata with XY staying in the background, eg

2025-03-27_103742.png
2025-03-27_103742.png (4.6 KiB) Viewed 2944 times

so something else might be causing it on your end, or the way you are implementing it. It's been my experience that when using copydata, XY usually only comes to the foreground when a dialog is called, unlike when using feed, then it always is shown.

MBaas
Posts: 654
Joined: 15 Feb 2016 21:08

Re: Feature Request: Run macro w/o bringing XY to foreground

Post by MBaas »

Ah, that's interesting. I can't call popupmeni directly - need to run it a .xys to build the menu first...

But...there is one simplet case where the menu should be in a file already, so I'll experiment with that.
_________________________________________________
Happy user with Screen scaling 100% and W11Pro 24H2 ;-)

jupe
Posts: 3296
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Feature Request: Run macro w/o bringing XY to foreground

Post by jupe »

Yeah I realize you were calling it via a script not directly, I was just demonstrating that the popupmenu itself wasn't the cause, it's the same when done via script, eg.

2025-03-27_165833.png
2025-03-27_165833.png (5.86 KiB) Viewed 2932 times

MBaas
Posts: 654
Joined: 15 Feb 2016 21:08

Re: Feature Request: Run macro w/o bringing XY to foreground

Post by MBaas »

Unfortunately I can't directy popupmenu, there is some work involved.
Here's is a simple case (which brings XY to foreground):

Code: Select all

/*******************************************************************************
@Author  : Michael Baas
@Created : February 2, 2025
@Modified: 
@Function: display the dyalog menu and launch selected
@Tags    : AppLauncher,Projects,Dyalog
@Title   : My AppLauncher (Project Menu)
@Version : v0.1
******************************************************************************/

    if (exists("C:\Program Files\Dyalog")) {// if dyalog is not disabled atm
       //$proj =  regexreplace($proj," *\&Enable Dyalog.*\r?\n","");
       $proj = readfile("<xyscripts>\AppLauncher-DyalogMenu_1.txt") 
    } else {// dyalog IS disabled...
       // $proj =  regexreplace($proj," *\&Disable Dyalog.*\r?\n","");
       $proj = readfile("<xyscripts>\AppLauncher-DyalogMenu_0.txt") 
    }
    $proj = $proj . readfile("<xyscripts>\AppLauncher-DyalogMenu.txt");
    if ("<curitem>" == "") {
        $proj =  regexreplace($proj,"^.*<curi" . "tem>.*$","");// don't use <curitem> when looking for it as a string
    } 
    $sel = popupnested($proj);
    end $sel == "";
    if (":" == substr($sel,0,1)) {
        $sel = substr($sel,1,strlen($sel)-1);
        $sel = replace($sel,"⋄⋄",";");
    } else {
        $sel = "run ". $sel;
    }
    load $sel, , "s";    
_________________________________________________
Happy user with Screen scaling 100% and W11Pro 24H2 ;-)

MBaas
Posts: 654
Joined: 15 Feb 2016 21:08

Re: Feature Request: Run macro w/o bringing XY to foreground

Post by MBaas »

I experimented by trying to convert the initial phase of that macro to a one-liner that I'm passing through WM_COPYDATA - it worked (<phew>) - but also brought XY to foreground...
_________________________________________________
Happy user with Screen scaling 100% and W11Pro 24H2 ;-)

klownboy
Posts: 4403
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440

Re: Feature Request: Run macro w/o bringing XY to foreground

Post by klownboy »

Hi jupe, I noticed in your pic that you use send.exe. send.exe popupmenu("1,2,3") and send "load '%CD%\pm.xys'" Is that a compiled AHK script or something similar using Send_WM_COPYDATA or viewtopic.php?p=227057#p227057?

jupe
Posts: 3296
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Feature Request: Run macro w/o bringing XY to foreground

Post by jupe »

Well we must have different ideas of what a simple case is, the script you posted isn't really runable for anyone without those text files, but anyway I left most of your script intact and just changed the readfiles to a file that should exist on anyones computer, and kept the rest of your script, but just added 1 line to create a popupmenu with a couple entries that are runable, and for me xy stays in the BG when I run it, if it doesn't work for you then you should be able to test it with the XY_Send that klownboy linked to, and if that works then you will know the issue is in your implementation of WM_COPYDATA. BTW the msg I am sending is just ::load 'file.xys';

Code: Select all

   if (exists("C:\Program Files\Dyalog")) {// if dyalog is not disabled atm
       //$proj = readfile("<xyscripts>\AppLauncher-DyalogMenu_1.txt") 
       $proj = readfile(<xytagdat);
    } else {// dyalog IS disabled...
       //$proj = readfile("<xyscripts>\AppLauncher-DyalogMenu_0.txt") 
       $proj = readfile(<xytagdat>);
    }

    $proj = listfolder(<xydata>, "*.ini", 1, <crlf>);  // ADDED ONLY THIS LINE JUST TO POPULATE THE MENU EASILY

    if ("<curitem>" == "") {
        $proj =  regexreplace($proj,"^.*<curi" . "tem>.*$","");// don't use <curitem> when looking for it as a string
    }
    $sel = popupnested($proj);
    end $sel == "";
    if (":" == substr($sel,0,1)) {
        $sel = substr($sel,1,strlen($sel)-1);
        $sel = replace($sel,"⋄⋄",";");
    } else {
        $sel = "run ". quote($sel);
    }
    load $sel, , "s";
@klownboy: It is actually an app my brother made for me with a lot of customization I asked him to implement, but I just tested the one you linked to, and it functions the same in this scenario. I used to use my own heavily customized ahk version I cobbled together from posts on the forum, I think the orig was called messenger, but I no longer do.

klownboy
Posts: 4403
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440

Re: Feature Request: Run macro w/o bringing XY to foreground

Post by klownboy »

Thanks jupe. Yes, I remember now, it's a version of "MessagetoXYplorer" that I have in my AHK startup file. I should be able to use what I currently have to display an XY script menu as long as XYplorer exists without "activating" it.

MBaas
Posts: 654
Joined: 15 Feb 2016 21:08

Re: Feature Request: Run macro w/o bringing XY to foreground

Post by MBaas »

@jupe Yeah, sory - that word "simple" was a bit off. (It was though, compared to the other candidates I have :whistle: - but I realize it was a bit oo much for the purpose of the excercise...

Thanks to you and @klownboy - I tried using highend's send - and indeed that works fine, so the issue was with my approach of sending :oops:

✅ Case closed.
_________________________________________________
Happy user with Screen scaling 100% and W11Pro 24H2 ;-)

MBaas
Posts: 654
Joined: 15 Feb 2016 21:08

Re: Feature Request: Run macro w/o bringing XY to foreground

Post by MBaas »

Finally I found it: this all happened in LibreAutomate and the ignorant user :oops: totally missed the fact that the findOrRun Method - if that is set, it all works! :oops:

(Sorry Don, how could I assume XY would ne a change when it totally innocent and works perfectly :oops: )
_________________________________________________
Happy user with Screen scaling 100% and W11Pro 24H2 ;-)

klownboy
Posts: 4403
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440

Re: Send script to topmost XY via WM_COPYDATA

Post by klownboy »

Hey Highend, is this exe a compile AHK script? I was curious because I was able to use my AHKstartup fie to accomplish the same thing as your exe (i.e., bring up an XYplorer menu without XY being active (only running in the background). However, using my startup file which uses SendFunction(MessagetoXYplorer) that you're familiar with, I'm only able to get the normal left mouse click working on my menu. If you remember I am also using DetectContextMenu() and setting a perm variable message to XY
MessagetoXYplorer := "::perm $rmb=1;" to determine if a right click is performed on the context menu. Using your exe in this thread, my left and right click function works in the menu being raised. I'm not sure if it's because of how or what you are detecting (i.e., that XYplorer WinExist). Obviously I can run your exe from my startup file with something like ^o:: run "D:\Tools\XYplorer\Scripts\XY_Send script.exe D:\Tools\XYplorer\Scripts\XYmenu_NESTED.xys", but I was hoping to use the existing code in the AHK startup file.

By the way, could anything be done to eliminate the hour glass coming up for some time in a situation like this (i.e., when a menu displays)?

highend
Posts: 14604
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Send script to topmost XY via WM_COPYDATA

Post by highend »

Hi Ken,

no, ofc this isn't an AHK script (otherwise it would be a 1/2 MB large file).
It's written in PureBasic...

The XY detection is using the Windows API (e.g.: hWnd = GetWindow_(hWnd, #GW_HWNDNEXT))
GetWindow_ (reduced by the "_" is an API function)

I haven't seen an hourglass (yet) when sending a script via this tool?
One of my scripts helped you out? Please donate via Paypal

klownboy
Posts: 4403
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440

Re: Send script to topmost XY via WM_COPYDATA

Post by klownboy »

Thanks highend. I hope all is well. Looking back, I should have realized that it wasn't AHK. I looked at the file size yesterday and I remember how small it was.

So both using your exe and my AHK startup file's SendFunction(MessagetoXYplorer) bring up the menu fine and normal left click works in both methods, but my right click only works if the menu is brought up by your exe. It has to be something in the way the context menu WinExist("ahk_class #32768")) is being detected or the right click is recognized when done in the menu. I'll test some more using my AHK startup file. If I can't get it to recognize the right click I can go with your exe. Thanks.

klownboy
Posts: 4403
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440

Re: Send script to topmost XY via WM_COPYDATA

Post by klownboy »

highend wrote: 28 Mar 2025 18:38 I haven't seen an hourglass (yet) when sending a script via this tool?
Yes, when I use the exe to display a XYplorer menu, I get the menu with an hourglass. The hourglass does not affect making a selection in the menu, but it does last about 5 seconds before it goes away.

Also, if I elect to cancel out (i.e., not use the menu) and click outside somewhere, the menu stays up and I am forced to actually make a selection to have the menu disappear. I've seen the same result in a few different menus. In case it make a difference, I'm opening the scripts via AHK ^o:: run "D:\Tools\XYplorer\Scripts\XY_Send script.exe D:\Tools\XYplorer\Scripts\XYmenu_NESTED.xys"

Post Reply