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

Features wanted...
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 »

Even a simple execution like: "XY_Send script.exe" $r = popupmenu("a|b"); e $r;
leads to an hourglass?

That you need to select an entry is normal.
Using SendMessage() (in my program) is waiting for a return, PostMessage() would have a whole world of other problems ;)
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 »

highend wrote: 29 Mar 2025 11:42 Even a simple execution like: "XY_Send script.exe" $r = popupmenu("a|b"); e $r;
leads to an hourglass?
If I run that from internally from "Run script" in XY it works with no hourglass. I can't get it to run from AHK or from the command line. Syntax or quoting issues. I tried putting that one liner script in a script file to run it but had no luck with that either.
highend wrote: 29 Mar 2025 11:42 That you need to select an entry is normal.
Using SendMessage() (in my program) is waiting for a return, PostMessage() would have a whole world of other problems
Could it not detect an Esc or a click outside or anywhere else but the menu and exit.

Edit 1: I thought I should also mention, there is no hourglass when running the same script using AHK. My only issue has been, not getting the right click mouse function to work and I suspect that's due to a focus or sequencing issue between sending the script, MessagetoXYplorer := "::load 'D:\Tools\XYplorer\Scripts\XYmenu_NESTED.xys';" and then sending MessagetoXYplorer := "::perm $rmb=1;"

Edit2: An interesting side note, if a menu started via the exe while some other program is active, clicking on the XY taskbar icon will close the menu without activating XY. And as expected, if XY happened to be acive when opening the menu, clicking anywhere outside the menu on XY, will close the menu.

Edit3: I can see why escaping or closing a menu would be difficult in this situation. But interestingly for a get around, click anywhere in the menu and drag the mouse anywhere else and the menu closes or we can simply add a menu item to close it which includes end 1;

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

Re: Send script to topmost XY via WM_COPYDATA

Post by jupe »

Regarding the hourglass, have you tried running it with your AHK script totally closed/disabled, I'd suspect the issue could be related to what you mentioned earlier, the menu detection in AHK. Usually popupmenus don't accept rclick, and since you say rclick works using this threads exe, that means you must be running both simultaneously.

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 »

Right again jupe, thank you and thank you again highend. When I run, "D:\Tools\XYplorer\Scripts\XY_Send script.exe" "D:\Tools\XYplorer\Scripts\XYmenu_NESTED.xys" from a command prompt - no hourglass and that worked with my AHK startup file still enabled. I was opening the menu using AHK with a command, ^q:: run "D:\Tools\XYplorer\Scripts\XY_Send script.exe D:\Tools\XYplorer\Scripts\XYmenu_NESTED.xys" I'd like to still use AHK as the starter for the exe though. Would there be an alternate way to start the exe still using AHK via a command or am I tied to using a Windows link?

Edit: I ran it via a Windows shortcut and the menu had the hourglass "D:\Tools\XYplorer\Scripts\XY_Send script.exe" "D:\Tools\XYplorer\Scripts\XYmenu_NESTED.xys" It was much slower as well. The command prompt method was immediate.

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 jupe, I actually have the AHK version fully working without the use of highend's exe file. It also does not have an hourglass. The only issue I have with the fully AHK version is that it doesn't recognize my right click of the mouse in a menu. As you may remember from the past, I have a bunch of XY menus that utilize both the left and right click of the mouse. With highend's exe the right click is recognized. I think the right click issue may be due to the use of 2 MessagetoXYplorer or sequnce or active window issue. I've extracted the applicable protions from my AHK startup file, but the following does work with AHK version2. Of course you have to change the script refered to.

Code: Select all

KeyHistory 0
ListLines false
#SingleInstance force
;SetTitleMatchMode 2
Persistent true
DetectHiddenWindows true

; using AHK only method
#HotIf WinExist("ahk_class ThunderRT6FormDC")
^o::
{
    MessagetoXYplorer := "::load 'D:\Tools\XYplorer\Scripts\XYmenu_NESTED.xys';"
    SendFunction(MessagetoXYplorer)
    return
}
#HotIf

#HotIf WinExist("ahk_class ThunderRT6FormDC") ; using highend's exe
^q::
{
   run "D:\Tools\XYplorer\Scripts\XY_Send script.exe D:\Tools\XYplorer\Scripts\XYmenu_NESTED.xys"
   return
}
#HotIf

#HotIf ((DetectContextMenu() = 1) && NOT(isMouseOver("ThunderRT6PictureBoxDC", [66,67,72,73])))
RButton::
{
    MessagetoXYplorer := "::perm $rmb=1;"
    SendFunction(MessagetoXYplorer)
    Click
    return
}
#HotIf

SendFunction(MessagetoXYplorer) {
    hWnd := WinExist("ahk_class ThunderRT6FormDC")  ;ORIG and right click works with highend's exe
    size := StrLen(MessagetoXYplorer)
    if !(StrLen(Chr(0xFFFF))) {
        data := Buffer(size * 2, 0)
        StrPut(MessagetoXYplorer, &data, size, "UTF-16")
    } else {
        data := MessagetoXYplorer
    }

    COPYDATA := Buffer(A_PtrSize * 3)                    ; Allocate memory
    NumPut("Ptr", 4194305, COPYDATA, 0)                  ; Store msgType in       : COPYDATASTRUCT.dwData
    NumPut("UInt", size * 2, COPYDATA, A_PtrSize)        ; Store size in          : COPYDATASTRUCT.cbData
    NumPut("Ptr", StrPtr(data), COPYDATA, A_PtrSize * 2) ; Store data (message) in: COPYDATASTRUCT.lpData

    return DllCall("User32.dll\SendMessageW", "Ptr", hWnd, "UInt", 74, "Ptr", 0, "Ptr", COPYDATA, "Ptr")
}

DetectContextMenu() {     ; Detects context menu, but for use only in XYplorer
If (WinExist("ahk_exe XYplorer.exe") && WinExist("ahk_class #32768")) {   ;works with highend's exe and using AHK method
    return 1    ; We've found a context menu in XYplorer
    } else {
    return 0
    }
}

isMouseOver(controlName, controlNums) {
    MouseGetPos ,,, &controlNameUnderMouse
    for each, controlNum in controlNums
    {
        if (controlNameUnderMouse = controlName . controlNum)
            return 1
    }
    return 0
}
Edit: Some of these last few entries could have went to the other threadviewtopic.php?p=228421#p228421 on this topic such that I wasn't clogging up highend's script.thread. If you (jupe or highend) want to move them, go ahead. Though here is probably better for historical purposes. I'm fine either way.

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 »

Yes I understood only RClick wasn't working from what you mentioned earlier, that was what I was referring to when I said you should be able to get it all to work via AHK. I have only had time for a quick cursory look at the AHK script and to me it looks like everything is working except for the Click event, ie the perm gets set ok (maybe late...), just no left click is triggered when RClicking, is that what you see? So a reverse rocker click seems like it could "work" ?

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. It's a difficult issue to troubleshoot. I tried running the AHK script ("control- q") with XY active and with stepping on. If I perform a normal left click the stepping box comes up but it does not with right click. I was trying to determine if the variable $rmb was set. I get no response at all right clicking. So I suppose that's telling me that the "click" set in AHK is not happening regardless of the perm variable being set or not. I'm going to modify the script such that the varible is not "unset" after the script is run to see if I can determine if it was set or not.

Yes, the reverse rocker click does work (i.e., hold left button down and click right button) to simulate a right click. I'm not sure how you figured that would work not being familiar with rocker click.

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 »

I placed some echos to detect the variable $rmb to see if it was being set in the AHK script and passed to XYplorerr. The value is "1" when I reverse right click the menu and the right click menu option works. I have to assume that since the variable $rmb is getting set and XY sees it, that part of the AHK script is working (i.e., the $rmb variable is recognized in the context menu being brought up in XYplorer). So, it seems the issue is the acual "click" done in AHK is not being performed on the XY menu. I'll have to try other methods of sending the "click" to XY.

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 »

Yes that is what I concluded too, I think if you put the hotkey and the Rbutton parts in separate ahk files it would also probably work, because I think the popupmenu being visible is stopping ahk getting to the evaluation of the RButton code until it is too late, I am no ahk expert so I won't be able to "help" any further than that sorry.

I realize you would want it all in 1 file otherwise there is no benefit, likely there is a way around this issue (threading..), but finding it might be a chore.

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 again for the input jupe. I spent way too much time yesterday on chatGPT trying to get it working (my first time ever using chatGPT for coding). It was actually helpful but no success. I'll try separating the messages to XYplorer to see if that works. Maybe first I'll do that using a "include" statement to another AHK script. That wouldn't be so difficult as far as running them at startup. By the way I'm not using popupmenu for this particular menu; it's just a regular menu structure with nested subs.

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 »

No I don't think a include will work because that basically just joins it, you need separate threads or separate ahk exe's running, one of them doesn't need to be persistent though. At least that is how I see the issue, and is one workaround.

Yes I just said popupmenu because it's basically the same as a multi script menu in this case, its a menu that awaits input.

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 »

I shouldn't have mentioned using "include" cause like you said it's basically like inserting a script into another. But anyway, I did break the scripts into separate ones and had no success. For sure, I'm not knowledgeable enough in AHK to do it. Getting the reverse rocker click consistently is rough going.

Highend, would you be interested in trying to do basically what you did with the Pure Basic script viewtopic.php?t=28500 but in AHK, preferrably in a script vs exe. Your exe is able to detect the AHK right click function as discussed above viewtopic.php?p=228442#p228442. Let me know if you think it's possible. I'd send you a few beers. You may say it's not possible or just not worth it in AHK. If not, that's more than fine, I'll just use a left click only menu.

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

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

Post by highend »

I am currently in Bulgaria, I will take a look at it when I’m back (9.th of April), ok?
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: Feature Request: Run macro w/o bringing XY to foreground

Post by klownboy »

Sounds good. Bulgaria, work or play? Even if it's work related, hopefully there's some play time. Stay safe.

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 just split it in 2, and it seems to work fine, of course this is just a crude split, if it was me doing it for long term use, I would put the SendMessge function in a separate file, and then send the message to that file via cli params that is only run on demand, but just as a proof of concept these 2 files work for me when both launched and running simultaneously as separate ahk scripts. highend will probably come up with a much better solution though.
Attachments
ahk.zip
(1.51 KiB) Downloaded 40 times

Post Reply