Home | Tutorials | Wiki | Issues
Ask Your Question

Get mouse click location and event

asked 2013-12-02 21:09:35 -0500

amptrofa gravatar image

updated 2013-12-04 08:09:47 -0500

I would like to put a callback on any mouse clicks in the World View. The callback requires the location of the mouse click.

Is this possible without modifying gazebo (system plugin?)? This question and answer is probably very similar to this question, although I am focused on mouse clicks, not key presses.

One idea I have is capturing clicks on a transparent GUIOverlay, but CEGUI is completely new to me so I'm not sure if this is viable. I'm also hoping there's a better solution I haven't been able to find yet.


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-11-26 23:55:50 -0500

jdddog gravatar image

Here's an example I got working today. Follow the system plugin tutorial to compile/run it.

#include <gazebo/math/Rand.hh>
#include <gazebo/gui/GuiIface.hh>
#include <gazebo/rendering/rendering.hh>
#include <gazebo/gazebo.hh>
#include <gazebo/gui/MouseEventHandler.hh>
#include <gazebo/common/MouseEvent.hh>

namespace gazebo
  class SystemGUI : public SystemPlugin

    // Destructor
    public: virtual ~SystemGUI()

    // Called after the plugin has been constructed.
    public: void Load(int /*_argc*/, char ** /*_argv*/)
            boost::bind(&SystemGUI::OnMousePress, this, _1));

    public: bool OnMousePress(const common::MouseEvent & /*_event*/)
        std::cout << "Mouse press detected!\n";
        return true;

  // Register this plugin with the simulator
edit flag offensive delete link more


Is this also possible with a GUIPlugin?

maxieckert gravatar imagemaxieckert ( 2016-01-25 08:48:20 -0500 )edit

Should be. Give it a try, and let us know if you run into any problems.

nkoenig gravatar imagenkoenig ( 2016-01-25 09:38:55 -0500 )edit

It should actually work better with GUI plugins than with System plugins. See [this](http://answers.gazebosim.org/question/8500/how-to-return-the-controlling-to-default-event-handler/) question and [this](https://bitbucket.org/osrf/gazebo/issues/1575/it-isnt-possible-to-filter-mouse-events-in) issue

chapulina gravatar imagechapulina ( 2016-01-25 15:11:29 -0500 )edit

When I try to compile the code, I am getting the following error. /usr/local/include/OGRE/Paging/OgrePagingPrerequisites.h:32:31: fatal error: OgrePrerequisites.h: No such file or directory #include "OgrePrerequisites.h" I have no clue if I have to install anything. Please, help.

vishnurs gravatar imagevishnurs ( 2017-03-31 06:53:48 -0500 )edit

Hi @vishnurs, could you start a new question describing the code you're trying to run, your Gazebo version and other relevant information? Thanks!

chapulina gravatar imagechapulina ( 2017-03-31 11:39:20 -0500 )edit
Login/Signup to Answer

Question Tools



Asked: 2013-12-02 21:09:35 -0500

Seen: 842 times

Last updated: Nov 26 '14