Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 05-21-2008, 02:11 PM   #1
Registered: May 2003
Location: India
Distribution: Ubuntu 7.04, Fedora Core 9
Posts: 168

Rep: Reputation: 30
Question How to convert relative mouse co-ordinates to absolute co-ordinates?

I want to record and play mouse events on my Linux machine.
Basically i store all the mouse events entered by the user into a text file. For this, i am simply reading the device file: /dev/input/event1 using read() and storing the events into a text file. While playback i read() the text file and write() the events to the device file /dev/input/event1.

Here's my code:

FILE *deviceConnection,*record_file;
struct input_event myEvent;

deviceConnection = fopen(argv[1], "rw");
record_file = fopen(argv[2], "rw+");

while (1) {
        // read from the device file into the input_event structure */
	fread(&myEvent, sizeof(struct input_event), 1, deviceConnection);
	// Write the events to the text file */
       fwrite(&myEvent, sizeof(struct input_event), 1, record_file);

FILE *record_file;
struct input_event myEvent;
char filename[128] ;
int devHandle = -1;

devHandle = open(argv[1], O_RDWR);
record_file = fopen(argv[2], "r+");

while (!feof(record_file))
	fread(&myEvent, sizeof(struct input_event), 1, record_file);
	if (myEvent.value != 0) {
		printf ("We are in Key Press \n");
		write(devHandle, &(myEvent), sizeof(struct input_event);

close (devHandle);
Now, i am able to record and play the mouse events but while playback the mouse events are played relative to the current mouse position. This is because a standard mouse supports only relative events (A mouse supports key events: EV_KEY and Relative events: EV_REL).

Note: Absolute events (EV_ABS) are supported by pointing devices like joysticks etc.

Now, i want to get absolute mouse co-ordinates so that the mouse events can be played accurately irrespective of the current mouse position.

How can i achieve this? Can i convert the relative mouse position to absolute position?

Last edited by montylee; 05-21-2008 at 02:12 PM.
Old 05-22-2008, 03:14 AM   #2
Registered: May 2003
Location: India
Distribution: Ubuntu 7.04, Fedora Core 9
Posts: 168

Original Poster
Rep: Reputation: 30
no replies
common guys help me please.
I think to solve this problem i only need to save the exact mouse pointer position at the time when recording is started. Then i can simply record the relative events as i am doing now and compute the absolute co-ordinates by adding them to the initial mouse pointer position.

The problem is how can i get the exact initial mouse co-ordinates when the recording is started...

Any ideas?


events, mouse, relative

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Absolute and relative paths Gins Linux - General 6 11-08-2008 09:48 PM
LXer: Absolute Linux is an absolute winner LXer Syndicated Linux News 0 08-07-2007 07:32 PM
Wacom tablet is in mouse mode instead of absolute mode saravkrish Linux - Hardware 2 12-01-2006 02:35 AM
relative to absolute path vishalbutte Programming 4 01-14-2006 04:17 PM
relative/absolute paths in Java djgerbavore Programming 2 10-26-2004 09:01 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:47 PM.

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