Skip to main content
Known Participant
November 26, 2008
Question

Get the point of my mouse click position

  • November 26, 2008
  • 3 replies
  • 1084 views
How do I get the x and y of where my mouse click is???
This topic has been closed for replies.

3 replies

Participating Frequently
November 27, 2008
Hi,

I wrote a few tools plugins for Illustrator. http://perso.orange.fr/jlg.outils

To make a new tool added to the Illustrator toolbox, you have to use the AIToolMessage structure.
In this structure, you find the mouse coordinates. Look into AITool.h.

This structure is used by toolMouseDown, toolMouseDrag, toolTrackCursor, toolSelect, toolMouseUp, toolDeselect.

For instance,

extern AIErr toolTrackCursor( AIToolMessage *message )
{AIErr error = kNoErr;
AIRealPoint myPos;

//When your tool is selected and
//each time, your mouse moves, myPos contain your mouse position.
myPos.h=message->cursor.h;
myPos.v=message->cursor.v;
...
}

JLG.
Kenji85Author
Known Participant
November 27, 2008
I am going to write a tool plugin, understand that I could receive mouse event, but how am mi going to retrieve my x and y ???
A. Patterson
Inspiring
November 26, 2008
This is a tricky one. If you've written a tool plugin, then you can receive events about mouse clicks & drags, but only if you tool is selected. If you want to receive this information at any given time, the answer is "you can't"...at least not with the API.

It is possible to use the OS to catch mouse movement and clicks, though you'll have to catch the document opened notifier and hook into the right window to get the events. This is fairly straight forward to do with Spy++ on Windows (not sure what the equivalent on Mac is) in order to figure out what the window structure is, at least until CS3. After that, CS4 is a mess to figure out -- there are so many permutations of window organizations because you can have tabbed or not-tabbed or floating-tabbed documents. We actually hook into to this kind of functionality through the OS to get mouse movements and while it does work (and not terribly hard), we haven't got it 100% on CS4.