Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want to write a program in Python runs on Ubuntu and moves the mouse cursor, just like a hardware mouse would. What should I try to connect to: X or GNOME? I am pretty sure that X would work, but I have heard that it is very low-level and difficult to use. Is there some sort of GNOME API for this sort of thing, or would I have to build my own version of GNOME with some added changes? Would it just be easier to emulate a mouse? Are any of these things possible?

share|improve this question
    
what is the purpose for controlling the mouse cursor? Do you want to control it inside your application or do you need your app to run in the background and control the mouse? Please explain your use case and goal so we can suggest solutions. I dont think what you are trying to do is hard at all, but we need more information. –  Aras Mar 6 '12 at 5:14
    
I once tried to make a GTK+ app to record/replay events, and one thing I ran across was Xtest (from the X libs). Though I never found any decent documentation on it. –  Githlar Mar 6 '12 at 7:10
1  
It's a standard part of the X libs that allows you to move the mouse, press keyboard keys, etc. Basically emulate all user input... supposedly. I never could figure out how to use it. –  Githlar Mar 6 '12 at 7:16

1 Answer 1

up vote 0 down vote accepted

There's an example using Xlib via ctypes.cdll in this ubuntuforums.org thread. The sequence of calls is LoadLibrary, XOpenDisplay, XDefaultRootWindow, XWarpPointer, XCloseDisplay.

share|improve this answer
    
But does this mean that it is impossible to control the mouse in GNOME or just harder/easier? –  InkBlend Mar 6 '12 at 21:39
1  
More complex, I think. See for yourself: the GTK+ source code includes a drag-and-drop test program within which you can manually perform a drag-and-drop. You can observe how your arrow key presses move the cursor by means of gdk_device_warp calls while your drag-and-drop motion is in progress. Specifically that is the gdk_device_warp call in gtk_drag_key_cb. –  minopret Dec 4 '12 at 19:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.