WM_COPYDATA running script with popoupmenu: can't use accelerators

Discuss and share scripts and script files...
Post Reply
MBaas
Posts: 684
Joined: 15 Feb 2016 21:08

WM_COPYDATA running script with popoupmenu: can't use accelerators

Post by MBaas »

I recently had an issue when I ran scripts by sending load commands using WM_COPYDATA: XY was brouight to foreground and the menu was opened. I didn't want XY in foreground and after incorrectly assuming it was an XY issue, I found that my code was the culprit (I had missed an optional flag that was set to its default and did that).

Now that this is done I have another problem: the selected accelerators for the menuitems don't work! When I open the menu, the focus stays on the active app and pressing keys will send them there instead of the menu. However, since the popupmenu command creates the menu, I don't think I have an option to handle focus before the call. But I imagine that must be a general problem for anyone using WM_COPYDATA to open menus. (Right?)

So is there a hack to deal with that or does it that only work with XY in foreground?

Just to avoid misunderstandings: here is an example of such a menu where the key 0 can be used to select the Shutdown option.
29-03-2025_13-04-38.png
To see the attached files, you need to log into the forum.
____________________________________________________________________________________
Happy user. Screen scaling 100% and W11Pro [Version 10.0.26200.7922], XY 28.30.0600 * * LinkTree

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

Re: WM_COPYDATA running script with popoupmenu: can't use accelerators

Post by highend »

You would need to spawn a process that looks for an upcoming #32768 class window to activate it _before_ doing the "sendmessage wm_copydata" part...
One of my scripts helped you out? Please donate via Paypal

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

Re: WM_COPYDATA running script with popoupmenu: can't use accelerators

Post by MBaas »

Sounds like fun :oops:
Thanks - I'll have a go!
____________________________________________________________________________________
Happy user. Screen scaling 100% and W11Pro [Version 10.0.26200.7922], XY 28.30.0600 * * LinkTree

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

Re: WM_COPYDATA running script with popoupmenu: can't use accelerators

Post by MBaas »

Uh, my head explodes!

I ended up with this:

Code: Select all

            // Starte einen Thread, der nach #32768 Fenster sucht
            var lookForMenuThread = new Thread(() => {
                // Warte kurz, um dem System Zeit zu geben
                Thread.Sleep(100);
                
                // Suche nach dem Popup-Menü Fenster
                wnd menuWnd = wnd.find("", "#32768");
				while (!menuWnd.Is0 || menuWnd.IsVisible) {
					menuWnd = wnd.find("", "#32768");
				}
				print.it($"Found #32768 window: {menuWnd}");
				// Aktiviere das gefundene Fenster
				SetForegroundWindow(menuWnd.Handle);
				menuWnd.Activate();
                
            });
            
            // Starte den Thread
            lookForMenuThread.Start();
			print.it("looking for 32768"); 
            // Sende 			die Daten an XYplorer
            WndCopyData.Send<char>(w, 0x00400001, s);
            print.it("send data");
But this doesn't do it - any keys I press end up in the app that had focus when I launched this app.

Unable to do more on my own, I asked AI and after a series of iterations it suggested that appearently it is not possible to send keystrokes to an app's popup if the app itself doesn't have focus.
But you seemeed to be confident it would work, so probably the AI hallucinated. But why isn't it working then?
____________________________________________________________________________________
Happy user. Screen scaling 100% and W11Pro [Version 10.0.26200.7922], XY 28.30.0600 * * LinkTree

Post Reply