Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically choose a context menu item in another app?

The target app is written in Delphi (win32 not .NET) and is closed-source.

The action I want to invoke is called Copy, but there is no obvious keyboard shortcut. (Ctrl+Insert does the wrong thing and Ctrl+C does nothing)

I can find my target HWND and persuade it to open the context menu (it responds to WM_RBUTTONDOWN/UP not WM_CONTEXTMENU). From the menu HWND I can even obtain the menu handle via MN_GETHMENU and find the menu item I want. I just don't know the details of how to "choose" the item. It doesn't help that the menu is "modeless", ie. its HWND is not owned, so I don't know which of many hidden TPUtilWindow windows is the real owner - otherwise I could probably just send it a WM_COMMAND and not even pop up the menu, which would be preferable.

Although I am sure it facilitates all sorts of hacks, I would prefer not to inject code into the target process.

Answers accepted in any language.

like image 505
Hugh Allen Avatar asked May 06 '09 01:05

Hugh Allen


1 Answers

Apparently you're able to send it WM_RBUTTONDOWN/UP messages and it responds. If so, can you also send WM_KEYDOWN/UP messages? As long as you know the structure of the menu and it doesn't change, try telling the app that someone's pressing the Down arrow X number of times and then hitting ENTER. That seems like the simplest solution to me...

like image 68
Mason Wheeler Avatar answered Nov 08 '22 02:11

Mason Wheeler