LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-06-2007, 02:10 AM   #1
boogy
LQ Newbie
 
Registered: Jan 2007
Posts: 7

Rep: Reputation: 0
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.
 
Old 02-06-2007, 07:34 PM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
You can do that with a simple X11 application.

Have a look at xeyes for example to see how it can be done.
 
Old 02-07-2007, 01:39 AM   #3
boogy
LQ Newbie
 
Registered: Jan 2007
Posts: 7

Original Poster
Rep: Reputation: 0
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.
 
Old 02-07-2007, 04:33 AM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
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 ...
 
Old 02-07-2007, 07:50 AM   #5
boogy
LQ Newbie
 
Registered: Jan 2007
Posts: 7

Original Poster
Rep: Reputation: 0
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.

Last edited by boogy; 02-07-2007 at 08:09 AM.
 
Old 02-07-2007, 09:42 AM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
man XQueryPointer
 
Old 02-08-2007, 01:40 AM   #7
boogy
LQ Newbie
 
Registered: Jan 2007
Posts: 7

Original Poster
Rep: Reputation: 0
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);
   }
}
 
Old 02-12-2007, 09:19 AM   #8
boogy
LQ Newbie
 
Registered: Jan 2007
Posts: 7

Original Poster
Rep: Reputation: 0
I need to that without using xlib, any help?
 
Old 02-12-2007, 10:01 AM   #9
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
Perhaps looking at code for directFB would give a clue...
 
Old 04-23-2009, 03:29 AM   #10
mustafamadni
LQ Newbie
 
Registered: Mar 2009
Posts: 3

Rep: Reputation: 0
Post 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
 
Old 04-27-2009, 04:59 AM   #11
mustafamadni
LQ Newbie
 
Registered: Mar 2009
Posts: 3

Rep: Reputation: 0
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);
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Change default position of the X cursor or get rid of it!!! thebover Linux - Software 2 04-30-2009 12:47 AM
typing on keyboard jumps to mouse cursor position iomari Linux - General 5 07-26-2007 03:03 AM
where to find global cursor settings? soldan VectorLinux 2 09-16-2006 06:03 AM
Could not open default cursor font 'cursor' at startx with slackware 10.2 bgryderclock Slackware 3 01-02-2006 10:36 PM
DocumentFilter. How to control cursor position? jansh Programming 0 01-26-2004 07:18 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration