5

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.

Hugh Allen
  • 6,509
  • 1
  • 34
  • 44
  • I feel there would be some security implications if something like that were possible, since that would mean one can fool apps into thinking they are getting input from the keyboard/mouse when in fact it's coming from another app! Cannot think of any concrete example right now though... – Paggas May 06 '09 at 02:04
  • If you're running untrusted apps you've already lost anyway. But that raises a point - this works on XP... I wonder if it'd work on Vista / 7? – Hugh Allen May 06 '09 at 02:31

1 Answers1

8

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...

Mason Wheeler
  • 82,511
  • 50
  • 270
  • 477