X11 & mouse emuloation

Discussion in 'C++' started by Martin Roos, Nov 27, 2003.

  1. Martin Roos

    Martin Roos Guest

    is it possible thru some libraries to move the mouse cursor under X11
    from a C++ program and to call "click" ?

    if anyone has a good link to a lib desc or anything, all help is welcome.

    [trying to create a bot that would emulate user behaviour on a website
    randomly clicking around and doing stuff like that.]
     
    Martin Roos, Nov 27, 2003
    #1
    1. Advertisements

  2. Could be that this is possible.
    But you have to ask the experts for X11 on how to do it.
    This group deals with Standard C++ only. Standard C++ doesn't have
    a screen or a mouse or X11 or something like that.
     
    Karl Heinz Buchegger, Nov 27, 2003
    #2
    1. Advertisements

  3. Could be that this is possible.
    I will say it would bee better to ask this in comp.os.linux.x but
    I do happen to know.

    I am writing a class to do just this it is already capable of all
    the things you want to do. I have two even. One uses the XTrap
    extention the other uses XTest. I can email you the source code if
    you want it. The code can also record input to a macro language.

    To use the XTrap class you must have the line 'Load "xtrap"' in
    the module section of your XF86Config-4 file and have the extention
    compiled and installed. It comes with XFree86 and is compiled if
    it is not disabled.

    here is example code for using the class:

    #include "send_event2.hh"

    int main() {
    X11_Send_Events hi;
    hi.set_window("Mozilla Firebird"); // Sets the Curent window to the a window matching
    // string. Returns zero on fail.
    hi.set_default_window_position(0, 24); // exactly what it says... :) X, Y.
    hi.window_to_front(); // Brings the window to the front and to the default
    sleep(1); // position.
    hi.button_toggle(3); // Toggles the mouse button of choise 1-5.
    sleep(1);
    hi.button_toggle(3);
    sleep(1);
    hi.button_click(1); // Clicks the mouse button of choise 1-5.
    sleep(1);
    hi.move_mouse(100, 200); // Move mouse x and y pixels.
    sleep(1);
    hi.move_mouse_absolute_window(200, 35); // Move mouse to asolute position from corner of
    sleep(1); // selected window. Uses top left corner.
    hi.move_mouse_absolute_screen(400, 300); // Move mouse to absolute postion from top left
    sleep(1); // corner of screen.
    hi.center_mouse_pointer_in_window(); // Centers the mouse pointer in the current window.
    sleep(1);
    hi.record_input_to_ostream (std::fstream*);// You must send the program a signal to get it
    // to exit from this loop.
    return 0;
    }
     
    Frederick Reeve, Nov 30, 2003
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.