[comp.sys.next] obtaining current mouse pointer location

garnett@cs.utexas.edu (John William Garnett) (02/24/91)

I've read the manual... I still don't know how to do what I want to do.

What is the simplest way to determine the current location of the mouse
pointer?  I'm not planning on doing this from inside an IB app. or Obj. C.
I just wanted to write a simple C program... the only thing it needs to
do is determine the current x,y coordinates of the mouse pointer.

I was thinking that PScurrentmouse() was what I needed but every attempt
I make at using it gives me a Bus error.  Help!

-- 
John Garnett
                              University of Texas at Austin
garnett@cs.utexas.edu         Department of Computer Science
                              Austin, Texas

aozer@next.com (Ali Ozer) (02/25/91)

In article <1128@nada.cs.utexas.edu> John William Garnett writes:
>What is the simplest way to determine the current location of the mouse
>pointer?  ...
>I was thinking that PScurrentmouse() was what I needed but every attempt
>I make at using it gives me a Bus error.  Help!

To be able to get the mouse location you need to have a connection to the
window server. Typically applications get a connection to the window
server when they are created, in the [Application new] call. Thus
inserting an [Application new] at the beginning of the program will
probably solve your problem. Or, using the dpsclient library, you can
create a connection to the window server without instantiating an
Application object, as the following example shows:

#import <stdio.h>
#import <dpsclient/wraps.h>

main ()
{
    int done;
    DPSSetContext(DPSCreateContext(NULL, NULL, NULL, NULL));
    do {
        float x, y;
	PScurrentmouse (0, &x, &y);
	printf ("%d, %d\n", (int)x, (int)y);
 	PSbuttondown (&done);
    } while (!done);
}

This approach might be good enough for just getting the mouse location,
however, it is not recommended if you wish to do any significant
communications with the server.  Other than the tiny overhead in creating
an Application object, using the kit won't slow you down any, and also
trying to use a raw dpsclient connection without the kit's error handling,
event, and drawing layers will be painful & messy.  You're also likely
to create programs that don't play nicely with other apps.

Ali, Ali_Ozer@NeXT.com