Trapping cursor coordinates in Javascript

Hello Everyone:
   I am attempting to trap cursor coordinates but I do not know how to make that happen.  Here is the short algorithm I hope to implement:
click object to select.
click new location for object to move to
move object to new location.
I think I know how to do the first, but I have no idea how to make Javascript report the coordinates of the mouse cursor when I click on the new location.
Please share with me any thoughts/documentation/snippets that might help.  I will greatly appreciate it.
TIA.
John

@John – if you are using InDesign CS5 (or above) I have something for you.
At least a proof of concept that will work. Tested with InDesign CS5.5.
The script will not read out any cursor coordinates.
Unfortunately we cannot do this…
Instead I am using:
one event listener,
an JPEG image already placed,
the placeGun
and the "afterSelectionChanged" event.
To test the script below, you need:
1.A The ESTK open, run the script from that
OR:
1.B Run the script with a keyboard shortcut from InDesign's Scripts Panel
2. An open document
3. An already placed JPEG image in the document (with a link status OK)
4. One single page item selected (no text selected, not more than one object selected)
This is just a proof of concept!
I did not consider moving a selection greater than one object, I needed at least ONE image placed in the document, I did not consider double sided spreads with a coordiante system set by page.
And: I really had fun writing this!
Here the script (ExtendScript/JavaScript):
//MoveSelectionTo_POSITION-OF-CURSOR_ProofOfConcept.jsx
//Uwe Laubender
//DESCRIPTION:Just a proof of concept. Some pieces missing!
#targetengine "MovePositionToCursor[Proof Of Concept ONLY]"
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
//SOME CHECKS:
if(parseFloat(app.version)<7){alert("Does not run in InDesign v. "+app.version);exit()};
if(app.documents.length == 0){alert("No document open!");exit()};
if(app.selection.length !== 1 && !app.selection[0].hasOwnProperty("baselineShift")){
    alert("This is a proof of concept! Does ONLY work with ONE page item selected. NOT TEXT!");
    exit();
if(app.documents[0].allGraphics.length == 0){
    alert("This is a proof of concept! Does ONLY work with AT LEAST ONE JPEG ALREADY placed!");
    exit();
moveSelection();
function moveSelection(){
var myDoc = app.documents[0];
var myOriginalSel = app.selection[0];
var myOriginalSelID = myOriginalSel.id;
for(var n=0;n<myDoc.links.length;n++){
    if(myDoc.links[n].status == LinkStatus.NORMAL && myDoc.links[n].linkType == "JPEG"){
        var myImage = File(myDoc.links[n].filePath);
        break;
if(myImage){myDoc.placeGuns.loadPlaceGun(myImage)}
else{
    alert("This is a proof of concept! Does ONLY work with AT LEAST ONE JPEG ALREADY placed!");
    exit();
app.addEventListener("afterSelectionChanged", doSomething);
app.select(app.documents[0].pageItems.itemByID(myOriginalSelID));
function doSomething(myEvent){
    try{
    app.removeEventListener("afterSelectionChanged", doSomething);
    var myNewID = app.selection[0].id;
    var myGeoBounds = app.selection[0].getElements()[0].geometricBounds;
    app.documents[0].pageItems.itemByID(myNewID).remove();
    app.documents[0].pageItems.itemByID(myOriginalSelID).move([myGeoBounds[1],myGeoBounds[0]]);
    app.select(app.documents[0].pageItems.itemByID(myOriginalSelID));
    }catch(e){};
Uwe

Similar Messages

  • Mouse cursor coordinates

    Is it possible to get mouse cursor coordinates when it is not on a Component?

    Whit SwingUtilities.convertPointToScreen(point, component), but you will still need to add a mouse listeners.

  • How can I create a box in the toolbar to dispaly cursor coordinates

    I would like to create a box in the acrobat toolbar to display cursor position coordinates relative to a user specified origin. How can this box be created and added to the toolbar? I'm just getting started with writing acrobat plugins.

    OK...
    You can create a floating palette using the ADM APIs that are documented in the SDK, and for which there are samples.
    Or use your OS platform APIs for doing windows...
    Leonard

  • How can I change the numeric format of the cursor coordinates display in LV 8.2

    Since LV 8.0 or so the cursor display window of a graph indicator seems to be a tree control. I couldn't find where to change the numeric format of the numbers displayed in that control. What did I miss?

    lecroy wrote:
    Maybe I'm not clear on what your looking for but I just use a property node and route the raw cursor data out to what ever function I want to run on it, then display it in a seperate field.  The nice thing with the property node is you can have multiple graphs linked together by one set of cursors all with different readouts. 
    Yes, of course that's an option and I guess I'll have to do it that way.
    The point is that I converted a pre-LV-8.x program to LV 8.5. In the program I had used the coordinates display field in the cursor legend to display the position, just the was the cursor legend is supposed to be used, IMO. And in pre-LV-8.x days it was possible to customize the numeric format property of the cursor legend (either directly or by property nodes). It seems that with LV 8.x NI chose to use a treeview control for the cursor legend. With that 'improvement' the numeric formatting flexibility was lost since now the conversion to the string content in the cursor legend's treeview is happening somewhere 'under the hood'.
    <rant> Why do they (NI) always try to 'improve' things (where nothing needs be improved) and sacrifice functionality on the way....? </rant>

  • How can I extract cursor coordinate in Adobe Photoshop for use in Action script?

    What I want to do in Photoshop (version CC, but I think this applies to any version) is label a point using count tool under my mouse's current position, and label it multiple times (for different labels). I have an action that essentially does this:
    (1) Add to count (under one label) (2) Switch to second label (3) Add to count (under second label) (4) Switch to third label (5) Add to count (under third label)
    And the problem is that I need to be able to have a variable in the action script that uses the cursor's current position (X and Y numbers) on the canvas to set these three points when the macro is activated. Currently I am only able to record the script using constant X, Y values (the same point is labeled over and over when I play the recorded action). I am able to extract the code for the action for editing (via xbytor2's suggestion in this forum:https://forums.adobe.com/thread/696989) and I see where the variable can go, I just don't know what exactly to put in place of the constant X, Y values that will let Photoshop input the mouse's current coordinates...
    Any ideas? Much appreciated!!

    You could use the pen tool set to path and create a single dot, then run the script to get the cursor positions and use that in your script.
    var strtRulerUnits = app.preferences.rulerUnits;
    var strtTypeUnits = app.preferences.typeUnits;
    app.preferences.rulerUnits = Units.PIXELS;
    app.preferences.typeUnits = TypeUnits.PIXELS;
    var doc = activeDocument;
    var workPath = doc.pathItems.getByName("Work Path");
    var pos = workPath.subPathItems[0].pathPoints[0].leftDirection;
    $.writeln("x = " + pos[0] + " y = " + pos[1]);
    doc.pathItems.getByName("Work Path").remove();
    app.preferences.rulerUnits = strtRulerUnits;
    app.preferences.typeUnits = strtTypeUnits;

  • Panel vs Cursor Coordinate​s

    I'm having a problem understanding the relationship between cursor
    position and front panel object positioning. I'm using the "get cursor
    position" vi to give me the coordinates on a 1024x768 monitor. But,
    when I plug those numbers into the "position attribute" for an
    indicator, it isn't even close to being in the right location. Why?
    What's the secret code? Is there a known grid for all front panels
    (1024x1024) ? And somehow I need to translate from my graphics card
    resolution?
    Thanks,
    Bill

    Bill,
    The cursor position you got is in screen coordinates
    (top-left cornor of your screen is 0,0, bottom-right
    corner is 1024,768). You have to convert it to client
    coordinate (top-left corner of the client area of your
    front panel is 0,0). And then convert to LabVIEW
    coordinate, a vertical shift of the toolbar height.
    And then you can use it for position attribute.
    If you're using LabVIEW5.1, you can download the
    screen to client convert following this link:
    http://gtoolbox.yeah.net
    George
    George Zou
    http://webspace.webring.com/people/og/gtoolbox

  • Cursor Coordinate​s & Rectangle Coordinate​s not matching

    hello!
    I am actually drawing a drawing a rectangle over xy graph using mouse clicking events and I need coordinates exactly the way it is extracted by cursor.The indicator ''coord2'' & ''cursor 0'' should give me same results.I need output of coord 2 to be like cursor 0.Hope i managed to convey my point.May be i have to manipulate with scale.Check the attachment.
    Solved!
    Go to Solution.
    Attachments:
    Untitled.png ‏139 KB
    Draw Rect on graph.vi ‏39 KB

    Sets,
    I attached a VI that will turn your mouse up and down coordinates that are by default in pixels to x-y coordinates.  I also noticed that you were only able to make a rectangle when you started in the upper left and ended in the bottom right so I added some logic so you can start and end anywhere and have the rectangle be drawn.
    I also noticed that when drawing the rectangle the corners were drawn slightly below and to the left of the cursor, is this the issue you were actually trying to fix?  I just looked into that a little bit but couldn't figure out why that was happening.
    Matt J
    Professional Googler and Kudo Addict
    National Instruments
    Attachments:
    Draw Rect on graph.vi ‏27 KB

  • Screen Resolution & Mouse Cursor Coordinate

    Hi,
    I would like to ask how to do the following with a java program:
    1. get the screen's resolution
    2. get the coordinate of the mouse cursor on the screen
    Thanks you very much.

    If you can use Java 1.5, the classjava.awt.MouseInfo might be what you need
    Thanks, it really works!
    Glad I could help.
    However, now i find that the method
    getScreenResolution() in class Toolkit is an abstract
    method. I would like to know how to implement this?
    You don't need to. There is a concrete implementation tailor-made for your particular platform ready waiting for you. You get it by calling the static method getDefaultToolkit:
    Toolkit tk = Toolkit.getDefaultToolkit();
    int dotsPerInch = tk.getScreenResolution();

  • How to trap cursor exception ?

    Hi All,
    I wrote PL/SQL by delcare , open ,fetch and close cursor and
    trap exception (when OTHERS ) at the end of program then I want
    program to check If cursor no record found then set variable
    to something .
    How to write exception in this case?
    thank you
    Mcka

    Hi,
    EXCEPTION
    WHEN NO_DATA_FOUND THEN ...
    Is that what you need?
    Rod West

  • Retrieve Mouse Coordinates by JavaScript

       Hi folks,
    is there a way to retrieve current mouse coordinates (x, y) by using client side JavaScript?
    thank you

    I would first like to know, how are you going to implement the drag-drop functionality within Adobe Form?

  • Trap cursor on textField?

    Hi,
    May by silly question,
    I need to trap user on the same field
    (textField) if he/she entered invalid data.
    Some functinality like "getFocuse()" needed.
    Thx
    Ali

    Got the answer. Thx

  • How do I convert the single x and y coordinates returned by a CWGraph Click event to the Cursor X and Y Positions?

    I am trying a work around for another problem.
    cwCSnapNearestPoint does not give me a CursorDown event (TrackMode = cwGTrackDragCursor). I need to know when the user has clicked on a Cursor. I need to figure out when the user has clicked on a cursor.
    The click event gives you coordinates as "Single" which are an OLE_XPOS_PIXELS. How do I convert to the Cursor coordinates (or vis a vis)?
    Or better yet is there another way to figure that a cursor has been clicked on (while using cwCSnapNearestPoint and TrackMode = cwGTrackDragCursor )

    Here are a couple potential fixes for the problem. If you are dealing with cursors on the graph, I would look into CursorChangeEvent, CursorMouseDown, CursorMouseUp, and CursorMouseMove. The ChangeEvent is triggered upon repositioning of the cursor. MouseDown triggers on the depression of a mouse button on a cursor, while MouseUp triggers on the button's release. MouseMove is triggered when the mouse is moved over a cursor. These each give X and Y positions in the arguments. If you used these and then made a Sanp to nearest point, you should have the coordinates before you sanpped to the point.

  • How to strore mouse coordinates in array

    Hi,
    I am using LaptopTouchpad to get cursor coordinates. I need to track all the coordinates while the cursor moving. But i am getting only present coordinates. i thought that to track coordinates, i need to store in an array. while doing that i am getting only present coordinates in all the index position of array.

    Post your VI so we can see how you are doing it now.

  • How do I obtain the coordinates from an active X IMAQ container from use in another part of a vi?

    Is their a simple way to read the screen coordinates from the IMAQ Active X container produced by the example NI code IMAQ_vi.llb so I can use them in another part of a program?
    Many thanks
    Nick

    What is confusing me is the ActiveX reference. Are you using a non-standard display, or are you assuming it is ActiveX? The standard display (WindDraw) is not ActiveX as far as I know.
    To get a cursor coordinate within the WindDraw window, use IMAQ WindLastEvent. You can input that you are looking for mouse clicks. The output will tell you where the last mouse click was.
    Bruce
    Bruce Ammons
    Ammons Engineering

  • How to add cursors on polar plot

    I want to add cursors on polar plot just like the XY graph has. I am new to LabVIEW and want to be able to move those cursors by mouse movements and get the respective Angle and Magnetude values. Since the polar plot is a picture I am unable to do the same. So my questions is;
    Can I add cursors on Polar plot? If not, then, is there any other way to do so?

    Hi!
    I've found an old post about you issue: http://forums.ni.com/t5/LabVIEW/the-best-way-to-make-a-nice-POLAR-plot-in-LV/td-p/115478 (but no easy solution is provided ).
    You can use an XY plot, of course, but it's up to you to convert your polar plot to the cartesian coordinate system of the XY plot and the way back for the cursor coordinates.

Maybe you are looking for

  • Can I make ichat automatically login to a status other than 'available' ?

    I really want iChat to login to either 'invisible' or 'at work' when I launch it from the dock, is this possible? Sorry if this is a common question; I tried to search but the terms are all very common and I didn't see an answer. Thanks

  • Choosing an external DVD burner all the time instead of the built in burner

    I have the Superdrive but prefer to use the external DVD burner to save wear and tear on the Superdrive. When I pop in a blank DVD to burn, the drop down menu appears and I have to manually click on the external DVD burner. Is there something in the

  • Error when install

    hi, I try to install a new NW EP, I set such file system below: /sapmnt 5G /db2 10G /usr/sap 5G But when I run sapinst, step in run a new one, reading control.xml file in /tmp,it stop automically. there is not any log such as "sapinst.log" found. Onl

  • Extension controls are invisible [HTML5, InDesign CC 2014]

    Hello, I'm getting mad while my extension controls are invisible on running extension right from IDE eclipse. I'm using Eclipse with Extension Builder 3. Even the boiler code which is generated by Extension Builder with a model button in InDesign wit

  • Sims 2 install

    i can't get sims 2 application to work---i get a message that the program needs at least 1 mb of space and that i should free up some hard drive space. but my hard drive shows (on finder) that i have 30 gb of space. any advice would be appreciated.