LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Cursor Global Position (https://www.linuxquestions.org/questions/programming-9/cursor-global-position-525984/)

boogy 02-06-2007 02:10 AM

Cursor Global Position
 
Hello all,

How can i get the global position of the cursor?
(i'm using c language, and suse 10.1 linux)

Thanks.

jlliagre 02-06-2007 07:34 PM

You can do that with a simple X11 application.

Have a look at xeyes for example to see how it can be done.

boogy 02-07-2007 01:39 AM

Thanks for your reply,

but this method use X11, i need another method.

i'm using the framebuffer to draw something on the screen(desktop), and i want to get the position of the cursor.

Can you help me?

Thanks.

jlliagre 02-07-2007 04:33 AM

Quote:

Originally Posted by boogy
i'm using the framebuffer to draw something on the screen(desktop), and i want to get the position of the cursor.

Then there is nothing I can do for you ...

boogy 02-07-2007 07:50 AM

Ok, Thank you.

Could you please give me an example on how to do that in X11 ?
or the name of the API?

I'v searched for that in the xeyes, but i didn't find the API.

jlliagre 02-07-2007 09:42 AM

man XQueryPointer

boogy 02-08-2007 01:40 AM

Thanks, and here is the code:

Code:

#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <assert.h>

int main (void)
{
  Display *dpy;
  Window root, child;
  int rootX, rootY, winX, winY;
  unsigned int mask;

  dpy = XOpenDisplay(NULL);
  assert(dpy);

  while (1) {
    XQueryPointer(dpy,DefaultRootWindow(dpy),&root,&child,&rootX,&rootY,&winX,&winY,&mask);
    printf("x=%d - y=%d\n", rootX, rootY);
    //sleep(1);
  }
}


boogy 02-12-2007 09:19 AM

I need to that without using xlib, any help?

gnashley 02-12-2007 10:01 AM

Perhaps looking at code for directFB would give a clue...

mustafamadni 04-23-2009 03:29 AM

Modift / Set (x, y) coordinates
 
Hi

I also used X11 to get x and y coordinates through XQueryPointer() in the same way as in above mentioned code.

Is there any way to work in lower level of XServer using HID (Hardware Interface Device). As I am intrested to control my joystick to move in my mentioned coordinates on display screen.

Thanks alot

madni
madni[AT]kth[DOT]se

mustafamadni 04-27-2009 04:59 AM

Hi
Here is another way to get x and y axis and other events of devices (dev/usb/hiddevX) for kernel 2.6.X
This is by using HID (Hardware Interface Device) events at hardware interface level.

/*
* Madni
* gcc -Wall -W events.c
* sudo ./a.out /dev/usb/hiddev0
*/

#include <stdlib.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <asm/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdint.h>

#include <linux/input.h>
#include <linux/hiddev.h>

#define EV_NUM 5

int main (int argc, char **argv) {

int fd = -1;
char name[256]= "Unknown";

/* ioctl() requires a file descriptor, so we check we got one, and then open it */
if (argc != 2) {
fprintf(stderr, "usage: %s event-device - probably /dev/input/evdev0\n", argv[0]);
exit(1);
}
if ((fd = open(argv[1], O_RDONLY)) < 0) {
perror("evdev open");
exit(1);
}
//------------- Device Name ---------------------------
char name[100];
if (ioctl(fd, HIDIOCGNAME(99), name) < 0)
perror("HIDIOCGNAME");
else
{
name[99] = 0;
printf("Device Name: %s\n", name);
}
//-------------- Read Events-------------------------------
struct hiddev_event ev[EV_NUM];

int i;
while (1) {
read(fd, ev, sizeof(struct hiddev_event) * EV_NUM);
for (i = 0; i < EV_NUM; i++) {
printf("%d : EVENT: PARAM %x : %d\n", i,ev[i].hid, ev[i].value);

}
}
close(fd);

exit(0);
}


All times are GMT -5. The time now is 12:17 AM.