Mouse coordinates on the screen

is it possible to get mouse coordinates on the screen? i want to make a program which makes screenshots of areas on the screen and i want use the mouse to mark them.
how could i do that? is it possible to get mousecoordinates even if the mouse is outside the java JFrame?
there must be a way! i searched in the forum but i found no answer.
please don't tell me i have to use jni, the app should be platform independent.

Yeah, basically there's no way to do this. This should be requested if it hasn't already (too lazy to check). It's not hard for sun to add, they just need to add it. Ok, anyway, I looked into it and see if there was a way to do this even somewhat reasonably in Java. I was very disappointed. I pretty much had no luck, but I did get a lame way of implementing this :P After some thought, this is what I ended up with:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MousePosition extends JFrame implements MouseMotionListener
    private int x = 0;
    private int y = 0;
    private boolean isAP = true;
    public MousePosition()
        setSize(300, 300);
        setLocation(200, 200);
        addMouseMotionListener(this);
        addMouseListener(new MouseAdapter()
            public void mousePressed(MouseEvent e)
                isAP = false;
        setVisible(true);
        try
            Robot r = new Robot();
            r.mouseMove(getLocation().x + 50, getLocation().y + 50);
            r.mousePress(InputEvent.BUTTON1_MASK);
        } catch(AWTException e) {}
    public void mouseDragged(MouseEvent e)
        System.out.println(e.getX() + getLocation().x + ", " + (e.getY() + getLocation().y));
    public void mouseMoved(MouseEvent e) {}
    public static void main(String[] args)
        new MousePosition();
}So it'll "lock" the program getting the absolute coordinates until you press the mouse, then you're free to do what you want. You could also do this with keyPressed or anything else you want. JNI would be the real solution as of now, until then I think sun should address the problem.

Similar Messages

  • My Late 2009 Model 10,1 running 10.8.5 frequently acts as though I have pushed the F11 button, but I haven't.  The cables are not loose.  Gently touching the mouse will get the screen back, but often it immediately goes to the F11 mode.

    My Late 2009 Model 10,1 running 10.8.5 frequently acts as though I have pushed the F11 button, but I haven't.  The cables are not loose.  Gently touching the mouse will get the screen back, but often it immediately goes back to the F11 mode.  Is this a hardware or software issue?  How can it be fixed?

    I called Apple.  The problem was caused by settings in Mission Control.  After changing all 4 of the Hot Keys (if that's the proper term) shown in the bottom half of the Mission Control window in System Preferences to "-" by clicking on the drop down menus, the problem went away.  Apple's help was excellent!

  • My mouse keeps moving the screen around.  How do I reanchor it

    My Mouse keeps moving my screen around.  How do I re-anchor it?

    Goto trackpad in sys pref and try reducing your tracking speed or goto universal access in sys pref and check the mouse and trackpad settings...try altering them to solve your problem

  • When I slide the mouse one way the screen gets huge.  How do I bring it back down?

    When sliding the mouse the screen will all of a sudden get huge.  What is causing this and is there a way to undo it?

    universal access zoom was turned off.  but, Went into settings of mouse and unclicked the zoom option.  That seems to have solved the problem I was having
    Thanks for the help

  • Bluetooth mouse buttons do not respond but the mouse icon on the screen follows mouse movements.

    Running 10.6.8 and replace my wireless mouse with a Microsoft 5000 Bluetooth.  It works fine and then all of the suddon the left, right and wheel will not work.  I replace with my usb apple mouse and it does the same.  I also tried my old apple wireless mouse and it does the same thing.  Can anyone shine some light on this issue.  In order to fix I must reboot the computer.

    I have test with my usb mouse and the same thing is happening as well.  It usually happens when I click on an input field in chrome or safari.

  • Get a Control coordinates in the Screen

    Hi all,
    I've a little problem... I'd like to display a ContextMenu when left clicking on a button. I've managed that part, but the context menu is displayed at the mouse position.
    What I'd like is to display the menu on the right of the button ( buttonXmax ) but I can't find the absolute X value of a control.
    Any ideas ?
    thanks before,
    Jonathan

    import javafx.application.Application;
    import javafx.event.*;
    import javafx.scene.*;
    import javafx.scene.control.*;
    import javafx.stage.*;
    import javafx.geometry.Side;
    public class ContextM extends Application {
        public static void main(String[] args) {
            Application.launch(args);
        @Override
        public void start(Stage primaryStage) {
            Group root = new Group();
            Scene scene = new Scene(root, 300, 250);
            final ContextMenu contextMenu = new ContextMenu();
            final MenuItem menuItem1 = new MenuItem("MenuItem1");
            final MenuItem menuItem2 = new MenuItem("MenuItem2");
            contextMenu.getItems().addAll(menuItem1, menuItem2);
            final Button buttonXmax = new Button();
            buttonXmax.setLayoutX(100);
            buttonXmax.setLayoutY(80);
            buttonXmax.setText("Get context");
            buttonXmax.setOnAction(new EventHandler<ActionEvent>() {
                public void handle(ActionEvent event) {
                    contextMenu.show(buttonXmax, Side.RIGHT, 0, 0);
            root.getChildren().add(buttonXmax);
            primaryStage.setScene(scene);
            primaryStage.show();
    }

  • My iMac screen is frozen, yet the mouse moves across the screen. I can not open anything up. I have restarted it a few times.

    The mouse keeps turning to spinning wheel. I think I have too many photos open on the desktop but I can not move them as the mouse can not pick them up

    If the Finder is bogged down by too many items on the Desktop, you may be able to free it up by hiding the preview icons. Click anywhere on the Desktop to select it, then press the key combination command-J, or select
    View ▹ Show View Options
    from the menu bar. In the dialog that opens, uncheck the box marked
    Show icon preview
    You may now be able to move the items off the Desktop. Otherwise, start up in safe mode and try again.

  • Moving the mouse on the screen

    Hello!
    I want to write a program (applet), which is able to move the mouse to several fixed coordinates on the screen (=another hompage) and it should also be able to click on some special places.
    Any Ideas (maybe class Robot?)??
    thanx
    chrsitian

    About your try-catch variable problem. I had a similar problem myself just a few days ago. If there was an exception, the variable wouldn't get initialized but I forgot to break out of the current method and I was hitting all kinds of errors about variables not getting initialized. All that it took to fix was a couple of 'return;' statements added in, like this:
    try
       foo = new Foo(); //On exception, this was not getting initialized
       method1();
       method2();  //you get the idea
    catch (Exception e)
       ErrorHandlingMethod();
       return; //this broke out of the current function
    }Now, return itself may not help you in your particular problem, but any sort of code that will return to some previous safe state and let you re-run the 'try' block will have the same effect.
    Hope this helps!

  • Inappropriate mouse event coordinates in the WebKit of HTMLLoader/StageWebView

    Hi,
    We have a desktp application which incorporates an HTMLRichTextEditor (implemented in HTML/JS and loaded into AIR).
    We have run into a big problem with text selection though. It seems that the both the HTMLLoader and the StageWebView are passing wrong mouse coordinates to the WebKit when the cursor is outside of the component.
    I've created a sample application which uses mx:HTML (which is a wrapper of the HTMLLoader) and a WebView class (a wrapper aroun StageWebView reference to which is given here).
    The application is located here in Dropbox. The source code of the app is here.
    The app was built with Flex 4.6 and ran in AIR 3.7
    The sample app has a WebView which loads loremipsum and HTML loading some dummy local HTML page. The HTML page uses the JS->AIR bridge to report the mouseevents to a function in AIR. In the snapshot below the selection was started from the first row and then slowly continued to the left. As soon as it reaches the green area the selection changes unexpectably. As it can be seen in the bottom right -> the WebKit has received a mouse event with incorrect coordinates. The reported mouse coordinates seem to be the mouse coordinates within the green component and the selection behaves like that. If the mouse is moved to the blue - the selection changes again (according to the coordinates in the blue area).
    The component which uses the StageWebView behaves in absolutely the same way.
    I'd assume that I have to post a bug but I decided to post here at first.
    I've tried a few workarounds in order to stop and ongoing selection or to change it's behaviour but none of them with any relevant success. Even disabling mouse children for the entire application has no effect on the selection once it's started.
    Any help and/or comments would be much appreciated.
    Thanks !

    Thank you for the heads up.  Do you know if this is a recent change in behavior with AIR (ie. does this occur in previous versions)?  Regardless, could you please open a new bug report on this over at bugbase.adobe.com? 
    Once added, please post back with the URL so that others affected can add their comments and votes and I can follow up internally.
     

  • What causes the screen to magnify when using wireless mouse in Safari?

    Sometime when clicking the mouse in Safari the screen will magnify.  Why?

    Check your Magic Mouse preferences. There's a preference for zooming the screen in Safari similar to the double tap zoom for iOS devices. You can change that configuration.

  • Macbook + 20" ACD mouse jumping all over the screen problem

    hi all,
    in need of help , my ACD plugged into my Macbook make's the mouse jump around the screen, unplugged no problems.
    tried with trackpad and external mouse still the same
    macbook 1.83/2gb ram - 10.5.1
    Help !

    Buy a Logitech Bluetooth mouse!! I have had no problems with my Logitech...it seems like more people have problems with the mighty mouse and magic mouse. That is my opinion. I have this mouse:
    http://store.apple.com/us/product/TQ089LL/A?fnode=MTY1NDA1Mg&mco=MTA4MzgwNzg

  • RegisterPointerInputTarget() breaks InjectTouchInput() on Windows 8.1 when the user physically touches the screen.

    This is a "working on Windows 8.0 but broken on 8.1" problem.
    My application is a full screen magnifier. When magnification is turned on, there is no longer a 1:1 relationship between touch screen coordinates and desktop coordinates.
    So I need a way to allow the user operate the computer, such as dragging or pinching something on the desktop (icon/window/whatever). So when they drag their finger(s) across the touch screen, I need to capture that, translate the touch coordinates from magnified
    pixels coordinates into original desktop pixels and then inject new input to the app. I also want the ability to capture the touch input and not pass it to the app (so I can have gestures/whatever to control the magnifier viewport location). I might also want
    to inject input when the user is not touching the real screen.
    So I am capturing all touch input RegisterPointerInputTarget() and simulating touch input using InjectTouchInput() (after translating coordinates from the screen to the magnified desktop).
    My code for simulating touch input works fine in isolation (as does the SDK sample). My code for capturing all touch input also works fine. However, if they are both used at the same time it’s not happy, although I am not getting any error codes back from the
    API.
    Specifically, attempts to simulate a touch and hold or a touch and drag are not working whenever the user is physically touching the real touch screen. Further diagnosis indicates that the touch input messages are not arriving in the target application. The
    moment the user physcially touches the screen, any simulated input in progress gets cancelled and all subsequent calls to InjecttouchInput() are ignored - but no error code is returned.
    Because I am capturing all real input using RegisterPointerInputTarget(), I would expect all real physical input to be redirected to my window (which it does) and be able to call InjectTouchInput() at any point to simulate input. The simulated input would go
    to the target app and not be captured by my own process.
    This all worked fine in Windows 8.0 but is broken in  windows 8.1.
    I have written a basic test application that does two things.
    1.       Uses RegisterPointerInputTarget() to consume all touch input.
    2.       Uses InjectTouchInput() to simulate some output. In this case, it just does a click, followed by a down, a drag and an up – which handily draws a line in the paint application if you arrange your windows carefully.
    If I run this, it works until you physically touch the screen with your finger. The moment you do this, InjectTouchInput stops working (no error code), but the paint app receives a mouse up and the line stops. The hwnd to capture all touch input does receive
    WM_POINTER... messages and I an returning 0 from this function (have tried other return codes, nothing makes any difference).
    So it looks like that if you use RegisterPointerInputTarget(), any physical input is captured, but it also breaks any simulated touch gestures that are currently in progress.
    Source code is below, which you can drop in as a replacement for the main .cpp file in your injecttouch sample code from the win8 sdk (and set uiaccess=true and code sign it!). It does it in two threads, however this doesn’t seem to matter, it does the same
    thing with one thread. Am I doing something wrong?  (and yes, I know that calling Sleep() is not wise - my real app doesn't do this)?
    - Mike.
    // allow use of Windows 8 headers
    #undef WINVER
    #define WINVER 0x0602
    #include "stdafx.h"
    #include <debugoutx.h>
    #include <process.h>
    * WinMain *
    * Application entrypoint *
    static HWND touch_hwnd = NULL;
    static ATOM touch_window_atom = NULL;
    LRESULT CALLBACK TouchThread_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    switch (message)
    case WM_CLOSE:
    DestroyWindow(hWnd);
    touch_hwnd = NULL;
    break;
    case WM_NCPOINTERUPDATE :
    case WM_NCPOINTERDOWN :
    case WM_NCPOINTERUP :
    case WM_POINTERENTER :
    case WM_POINTERLEAVE :
    case WM_POINTERACTIVATE :
    case WM_POINTERCAPTURECHANGED :
    case WM_TOUCHHITTESTING :
    case WM_POINTERWHEEL :
    case WM_POINTERHWHEEL :
    // case DM_POINTERHITTEST :
    case 0x250:
    case WM_POINTERUPDATE :
    case WM_POINTERDOWN :
    case WM_POINTERUP :
    // consume pointer mesages
    dprintf(L"msg %x\n",message);
    return 0;
    break;
    case WM_TIMER:
    break;
    default:
    dprintf(L"msg %x\n",message);
    return DefWindowProc(hWnd, message, wParam, lParam);
    break;
    return 0;
    void Inject(POINTER_TOUCH_INFO &contact)
    Sleep(1);
    while(1)
    DWORD bRet = InjectTouchInput(1, &contact);
    if (bRet==0)
    DWORD temp = GetLastError();
    if (temp==ERROR_NOT_READY)
    Sleep(1);
    continue;
    else
    DebugBreak();
    break;
    static int start = 400;
    static int end = 800;
    bool SimulateInput(POINTER_TOUCH_INFO &contact)
    static int x = start;
    if (x==start)
    contact.pointerInfo.ptPixelLocation.x = x;
    // inject a touch down
    contact.pointerInfo.pointerFlags = POINTER_FLAG_DOWN | POINTER_FLAG_INRANGE | POINTER_FLAG_INCONTACT;
    Inject(contact);
    else if (x==(start+1))
    Sleep(10);
    contact.pointerInfo.pointerFlags = POINTER_FLAG_UP ;
    Inject(contact);
    else if (x==(start+2))
    contact.pointerInfo.pointerFlags = POINTER_FLAG_DOWN | POINTER_FLAG_INRANGE | POINTER_FLAG_INCONTACT;
    Inject(contact);
    else if (x==end)
    contact.pointerInfo.pointerFlags = POINTER_FLAG_UP ;
    Inject(contact);
    PostMessage(touch_hwnd,WM_QUIT,0,0);
    return false;
    else if (x<end)
    // drag
    contact.pointerInfo.ptPixelLocation.x = x;
    // contact.rcContact.left = x - 4;
    // contact.rcContact.right = x + 4;
    contact.pointerInfo.pointerFlags = POINTER_FLAG_UPDATE | POINTER_FLAG_INRANGE | POINTER_FLAG_INCONTACT;;
    Inject(contact);
    x++;
    return true;
    void thread2(void *)
    // create window to capture global touch input.
    if (!touch_window_atom)
    WNDCLASS wc;
    wc.style = 0; // Class style(s).
    wc.lpfnWndProc = TouchThread_WndProc; // Function to retrieve messages
    wc.cbClsExtra = 0; // No per-class extra data.
    wc.cbWndExtra = 0; // No per-window extra data.
    wc.hInstance = GetModuleHandle(0); // Application that owns the class.
    wc.hIcon = NULL;
    wc.hCursor = NULL;
    wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName = NULL; // Name of menu resource in .RC file.
    wc.lpszClassName = L"MarsTouchInputCapture"; // Name used in call to CreateWindow.
    // Register the window class and return success/failure code.
    touch_window_atom = RegisterClass(&wc);
    touch_hwnd = CreateWindowEx(WS_EX_NOACTIVATE,L"MarsTouchInputCapture",L"Magnification",0,0,0,1,1,NULL,NULL,GetModuleHandle(0),NULL);
    // capture global desktop touch input
    if (RegisterPointerInputTarget(touch_hwnd,PT_TOUCH)==0)
    DWORD err = GetLastError();
    MessageBox(NULL,L"RegisterPointerInputTarget(PT_TOUCH) failed",L"error",MB_OK);
    if (RegisterPointerInputTarget(touch_hwnd,PT_PEN)==0)
    DWORD err = GetLastError();
    MessageBox(NULL,L"RegisterPointerInputTarget(PT_PEN) failed",L"error",MB_OK);
    // message loop
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0))
    DispatchMessage(&msg);
    UnregisterPointerInputTarget(touch_hwnd,PT_TOUCH);
    UnregisterPointerInputTarget(touch_hwnd,PT_PEN);
    int
    WINAPI WinMain(
    _In_ HINSTANCE hInstance,
    _In_opt_ HINSTANCE hPrevInstance,
    _In_ LPSTR lpCmdLine,
    _In_ int nShowCmd)
    POINTER_TOUCH_INFO contact;
    BOOL bRet = TRUE;
    MessageBox(NULL,L"Break on Load",L"Attach Debugger",MB_OK);
    // assume a maximum of 10 contacts and turn touch feedback off
    InitializeTouchInjection(10, TOUCH_FEEDBACK_NONE);
    // initialize the touch info structure
    memset(&contact, 0, sizeof(POINTER_TOUCH_INFO));
    contact.pointerInfo.pointerType = PT_TOUCH; //we're sending touch input
    contact.pointerInfo.pointerId = 7; //contact 0
    contact.pointerInfo.ptPixelLocation.x = 400;
    contact.pointerInfo.ptPixelLocation.y = 480;
    contact.touchFlags = TOUCH_FLAG_NONE;
    contact.touchMask = TOUCH_MASK_ORIENTATION | TOUCH_MASK_PRESSURE;
    contact.touchMask = 0;
    contact.orientation = 90;
    contact.pressure = 32000;
    // create thread/window for global capture
    _beginthread(thread2,0,NULL);
    while(SimulateInput(contact))
    Sleep(1);
    return 0;

    I have almost same situation. But there are some different. I am using RegisterPointerInputTarget to redirect all touch message to my window. and use InjectTouchInput to simulate each flag, which means, WM_POINTERDOWN,WM_POINTERUPDATE,WM_POINTERUP. If user
    touches monitor, I simulate DOWN, if user swipes their finger, I simulate UPDATE, if user lifts finger, I simulate UP.
    Then the interesting point is, system consider user's finger as primary pointer, and my injected touch as secondary pointer. windows desktop and windows explorer skip all my injected touch. I really hate that.
    However IE and chrome will accept my injected touch, they don't caret about primary pointer.
    In order to fix this problem, I call AccNotifyTouchInteraction before calling InjectTouchInput.
    According to the MSDN, AccNotifyTouchInteraction will notify the destination window before InjectTouchInput. But this idea still fails, which is disappointing.

  • Get Mouse Coordinates

    Is there any method that gives me the Mouse Coordinates ?
    I want something that when i click the mouse button it gives me the mouse coordinates. So what i really want are 2 methods, one that detects that the mouse button has been pressed, and another that gives me the Mouse Coordinates.

    Hi,
    you can use the MouseEvent class, it has a getX() and getY() method that returns an int representing the coordinate on the screen the mouse is at. You can access the MouseEvent class through the MouseAdapter or MouseListener. Using either MouseAdapter or MouseListener will give you access to mouseClicked method, used to handle mouse click events.

  • Mouse coordinate in oracle form canvase

    Hi,
    Is there any way to know the mouse coordinate when the mouse is moving in oracle form canvase.
    I will appreciate for help..... Thanks.
    Regards,

    System variables should give u information
    this forms example might help
    /* Trigger:  When-Mouse-Click
    **   Example:  Dynamically repositions an item if:
    **             1) the operator clicks mouse button 2
    **                on an item and
    **             2) the operator subsequently clicks mouse button
    **                2 on an area of the canvas that is
    **                not directly on top of another item.
    DECLARE
       item_to_move       VARCHAR(50);
       the_button_pressed VARCHAR(50);
       target_x_position  NUMBER(3);
       target_y_position  NUMBER(3);
       the_button_pressed VARCHAR(1);
    BEGIN
       /* Get the name of the item that was clicked.
       item_to_move := :System.Mouse_Item;
       the_button_pressed := :System.Mouse_Button_Pressed;
       **  If the mouse was clicked on an area of a canvas that is
       **  not directly on top of another item, move the item to
       **  the new mouse location.
       IF item_to_move IS NOT NULL AND the_button_pressed =  '2' THEN
          target_x_position := To_Number(:System.Mouse_X_Pos);
          target_y_position := To_Number(:System.Mouse_Y_Pos);
          Set_Item_Property(item_to_move,position,
              target_x_position,target_y_position);
          target_x_position := NULL;
          target_y_position := NULL;
          item_to_move := NULL;
       END IF;
    END; plz mark correct/helpful if it is

  • Why does the screen "wash out" with the statement "Firefox is not responding" This happens at least once in each session.

    I am not sure what more details I can provide. Suddenly, the cursor for the mouse will freeze, the screen washes out. You can still see the underlying webpage faintly. After a few seconds, the problem corrects itself and Firefox resumes normal operation. This happens with the new Firefox 4 as well as the previous version.
    It is major annoyance.

    My situation got worse. FF 3.6.12 started doing that; then it just stopped loading. Since then, I have uninstalled & reinstalled, moved my profile to force it to make new one, set it so that it is not the default browser, installed in different drive on computer, cleaned out regedit, ran a spyware program, & nothing. It starts to load then hangs up almost immediately. This has been going on for about 3 days & I'm about ready to chunk it. Any ideas?

Maybe you are looking for

  • How to fix the iphone 4s if it is the wrong carrier iphone 4s?

    Just wondering if anyone has had this problem and how to fix it.   Lets see in October 2012 I bought a brand new Iphone 4s.   I had it less than a week when I sent it to Apple because it had already been updated to IOS 6 without my knowledge and the

  • Questions about OLE containers

    Hello, I try to use an OLE container for save any type of documents, the majority are Microsoft Word (*.doc), Acrobat Reader (*.pdf) and images (*.jpeg, *.jpg, *.bmp, ...) I prove to insert a document an save it in the database and all works fine. Th

  • Screen sensitivity issues

    I'm having a problem with the screen sensitivity on my iPad. There seems to be a certain area on the screen that is dead to the touch. When I try to file up or down in that area it won't work. But if I move over a bit, my touch is then recognized. So

  • CONDITION TYPE ATTACHED

    Sir, Condition type Manual Processing not allowed in that i want to apply for multiple Pricing procdeure.in M/06 how is it possible or any recommendatios onit. Ex:let say there are 3 procedures in which i only want Manual processing not allowed for t

  • Recording Vocals to ipod nano

    Hello, Can i use my ipod nano to record my voice and conversation directly to the ipod?