Skip navigation
Currently Being Moderated

Register an event for illustrator document.

Mar 28, 2012 6:50 AM

Hi guys,

 

Is there an any api to register the mouse click event or something on the illustrator document?

 

Any help would be appreciated.

 
Replies
  • Currently Being Moderated
    Mar 28, 2012 7:01 AM   in reply to AI_learner

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 26, 2013 4:22 AM   in reply to A. Patterson

    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!

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 26, 2013 4:42 AM   in reply to Egor Malanichev

    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!

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 26, 2013 5:10 AM   in reply to A. Patterson

    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!

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points