1 person found this helpful
No, there's no way to do that with the SDK. That said, you can determine the window handle for the document with a little work (though it will vary from version to version of AI) and grab OS-specific events like clicks & movement. If you're hoping to pop up a custom menu though, you're out of luck. If you want to know where the mouse is or when its clicking, that you can do with a little work.
Could you please elaborate on how to do that workaround? (the goal is to get a mouse clicked event when a user clicks on a document, and get the x and y coordinates of that event). Any help appriciated. Thanks!
I can only help yo uwith Windows; its very different on the Mac.
The first thing to do is to find the document's HWND first. You can do that by keeping track of all the 'OWL.Document' window classes; these are the document windows. The best way is to catch the document opened & closed notifiers and see which OWL.Documents appear & disappear as documents are opened & closed. That will let you associate the correct starting point with the current document. As a side note: when looking, you'll need to look in two different ways in CS6+ becuase of the way they organized the tabbed documents in CS6. So you might think you have it all working and then find that it doesn't seem to work if you undock the current document -- just a head's up!
Once you have the document's HWND, you'll need to figure out which child is the one that's getting all the mouse events. That'll depend on what version of AI you're running -- CS5 & CS6 are different (CS4 might be the same as CS5, can't remember, its been a while). The best way to tell is to fire up Spy++ and once you know the parent document window, just stick the message watch on different children (it'll be near the top of the hierarchy) and watch for mouse events when you move your mouse over the document window. Once you know which one it is, it shoudn't be too hard to install a mouse hook on that window (we use SetWindowLongPtr() to get all messages). Obviously, you'll need uninstall & reinstall the mouse hook every time the document changes and/or closes. Once you have the hook though, you just need to watch for whatever click event you want and grab the mouse location (we track WM_MOUSEMOVE because we just want to know where the mouse is, not where it clicks, naturally you'd want something like WM_MOUSEUP).
The coordinates will be in document coordinates so you'll need to use AIDocumentView::FixedViewPointToArtworkPoint() if you want to know the artboard coordinate, but maybe you're okay with the document pixel coordinate, I don't know
Anyways, hope that helps! Mac is similar, but the window methods & strucutres are different -- same idea though: find the right window and listen to its mouse events!
Thanks a lot! Its only my forth day working with CS plug-ins and i'm working on MAC, so it will take me some time to figure it out, but you gave me great guidance where to look at! Thanks!