How to simulate mouse click?
- HakanSeven12
- Veteran
- Posts: 1458
- Joined: Wed Feb 06, 2019 10:30 pm
How to simulate mouse click?
I want to simulate mouse click at given coordinate. How can I do that?
Support me: Hakan Seven on Patreon
Modern UI: Modern UI on FreeCAD Forum
Trails Workbench: Trails Workbench on FreeCAD Forum
Modern UI: Modern UI on FreeCAD Forum
Trails Workbench: Trails Workbench on FreeCAD Forum
Re: How to simulate mouse click?
Unfortunately QTestEventList isn't available in PySide.
You could try to use QtGui.QApplication.sendEvent(), but I doubt it will really work.
You could try to use QtGui.QApplication.sendEvent(), but I doubt it will really work.

Re: How to simulate mouse click?
HakanSeven12 wrote: ↑Mon Mar 09, 2020 7:56 am I want to simulate mouse click at given coordinate. How can I do that?
Code: Select all
from PySide2 import QtCore
from PySide2 import QtGui
from PySide2 import QtWidgets
mw = Gui.getMainWindow()
gl = mw.findChild(QtWidgets.QOpenGLWidget)
me = QtGui.QMouseEvent(QtCore.QEvent.MouseButtonRelease, QtCore.QPoint(800,300), QtCore.Qt.LeftButton, QtCore.Qt.LeftButton, QtCore.Qt.NoModifier)
app = QtWidgets.QApplication.instance()
app.sendEvent(gl, me)
Re: How to simulate mouse click?
Adding to Code snippets, yo!wmayer wrote: ↑Mon Mar 09, 2020 9:42 amThe position is relative to the GL widget.HakanSeven12 wrote: ↑Mon Mar 09, 2020 7:56 am I want to simulate mouse click at given coordinate. How can I do that?
Edit:
Done in Code snippets#How_to_Simulate_a_Mouse_Click_at_a_given_Coordinate
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
- HakanSeven12
- Veteran
- Posts: 1458
- Joined: Wed Feb 06, 2019 10:30 pm
Re: How to simulate mouse click?
Is there a way to use 3d view coordinates?
Support me: Hakan Seven on Patreon
Modern UI: Modern UI on FreeCAD Forum
Trails Workbench: Trails Workbench on FreeCAD Forum
Modern UI: Modern UI on FreeCAD Forum
Trails Workbench: Trails Workbench on FreeCAD Forum
Re: How to simulate mouse click?
If you have a 3d point and want to get the 2d point on the opengl widget then use this:
Code: Select all
from FreeCAD import Base
v = Gui.ActiveDocument.ActiveView
point3d = Base.Vector(x, y, z)
point2d = v.getPointOnScreen(point3d)
size = v.getSize()
coordX = point2d[0]
coordY = size[1] - point2d[1]
...
me = QtGui.QMouseEvent(QtCore.QEvent.MouseButtonRelease, QtCore.QPoint(coordX,coordY), QtCore.Qt.LeftButton, QtCore.Qt.LeftButton, QtCore.Qt.NoModifier)
- HakanSeven12
- Veteran
- Posts: 1458
- Joined: Wed Feb 06, 2019 10:30 pm
Re: How to simulate mouse click?
Thank you

Support me: Hakan Seven on Patreon
Modern UI: Modern UI on FreeCAD Forum
Trails Workbench: Trails Workbench on FreeCAD Forum
Modern UI: Modern UI on FreeCAD Forum
Trails Workbench: Trails Workbench on FreeCAD Forum