Gazebo | Ignition | Community
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

2 Answers

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]( question and [this]( 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

Your code works fine, thanks, but along with 'mouse press detected' , I want to print the coordinate value in the console, anyone have any idea how I can do this? TIA

voila gravatar imagevoila ( 2022-06-17 00:29:00 -0500 )edit

answered 2021-09-24 14:30:39 -0500

gzp-gz gravatar image

It's not an answer but a question. I am new to gazebo plugin. A question I have is this: I build this plugin using the code above. Build is good. I have also create a launch file and a .world file in which a line "<plugin name="mmr_sim_input_mouse_plugin" filename=""/>" added. when I launch it, I saw the destructor got called. I have ROS_WARN in Load and Init but no warning messages printed out. Anyone could share an idea for this? Thank you very much.

BTW, if I do as below, it is working fine (Load, Init and OnMousePress all print out ROS_WARN messages) if I run gzserver & and gzclient -g

edit flag offensive delete link more

Question Tools



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

Seen: 1,978 times

Last updated: Sep 24 '21