Page 1 of 1

WM_COPYDATA running script with popoupmenu: can't use accelerators

Posted: 29 Mar 2025 13:03
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
29-03-2025_13-04-38.png (5.02 KiB) Viewed 4665 times

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

Posted: 29 Mar 2025 13:20
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...

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

Posted: 29 Mar 2025 14:12
by MBaas
Sounds like fun :oops:
Thanks - I'll have a go!

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

Posted: 29 Mar 2025 16:04
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?