According to this and to your previous question, you want to deactivate your tool by pressing the Escape key.
However, as far as I know, one cannot deactivate a map tool. One should activate another map tool to deactivate (indirectly) the current one. That is, the map canvas MUST always have an active map tool. So, in order to deactivate your map tool you must activate another one. For the sake of showing an example, I've chosen the Pan map tool.
If you were to activate the Pan map tool, you would use:
iface.actionPan().trigger()
So, let's say you want to activate the Pan map tool when pressing the Escape key, which would in turn deactivate your custom tool.
You can use the following code snippet to link the Escape key press event to the Pan map tool activation:
from PyQt4.QtGui import QShortcut, QKeySequence
from PyQt4.QtCore import Qt
shortcut = QShortcut(QKeySequence(Qt.Key_Escape), self.iface.mainWindow())
shortcut.setContext(Qt.ApplicationShortcut)
shortcut.activated.connect(self.iface.actionPan().trigger)
Since you are writing a QGIS plugin, you could put the code snippet into your plugin's main Python module (let's say main.py
), for instance, in your initGui()
method.