C++ and moving the mouse...

N

Narcolessico

Hi,
I'm writing on Linux an application which needs to move the mouse pointer
and simulate button clicks (better: button press and release events
separately, e.g. to do drag&drop).
I found several ways to move the pointer:
- Using QT QCursor::setPos
- Using SDL libraries
....
- Using XLib directly

Now the problem is... I can move it, but I can't really simulate clicks.
On Qt, I don't know to who I should send the mouse motion event ( I tried to
send it to the application itself, but it doesn't work), because I don't
have any interface (it is a command line app).

With Xlib, I can move the cursor with XWarpPointer, but it seems to reset
the button state. I send a button press event with the code I found here:

http://snippets.dzone.com/posts/show/2750

but as soon as I call XWarpPointer, the button status is reset and the click
results in only a point. If a drawing application has the focus, I would
draw on it; unfortunately, I only see points.

I also tried to send XMotionEvents instead insted of using XWarpPointer, but
nothing changes. I tried to create new events each request (instead of
using the same pointer), and to call XFlush and XSync after each request...
But I can see only points.

How can I simulate a mouse motion by keeping the mouse button pressed in
C++? Which library shall I use? Any tip for Xlib or QT?
 
V

Victor Bazarov

Narcolessico said:
[..]
How can I simulate a mouse motion by keeping the mouse button pressed
in C++? Which library shall I use? Any tip for Xlib or QT?

Tips on Xlib and Qt are off-topic, sorry. Here we talk C++ language
itself, which incidentally does not define any ways to control mouse
or any other hardware for that matter. Try the newsgroup for your OS.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top