I have a Python Traits app which consists in a instance of the HTML class (to say short).
In this instance, I have a leaflet map.
That works fine (it displays a leaflet map).
I know how to catch keyboard shortcut in leaflet, for instance:
document.addEventListener('keydown',
function(event)
{if (event.ctrlKey && event.key === 's')
{alert('Ctrl + s pressed!');}});
That works fine.
What I want to do is catching leaflet event and send it to my Traits app.
I tried something like this:
document.addEventListener('keydown', function(event) {
if (event.ctrlKey && event.key === 's') {
var event = new CustomEvent('ctrl_s_pressed');
document.dispatchEvent(event);}});
for the leaflet part,
and
ctrl_s_pressed = Event
def _ctrl_s_pressed_fired(self):
print('Ctrl-s pressed')
for the Python/Traits part.
But this does not work: no message displayed from my Traits app.
Any hint?
TIA