Respond to keyboard events in config screen

Hi folks,

I have an SVG in the config screen of a new node, and when spending my time in that SVG I need to be able to respond to keyboard events.

  1. Since an SVG element is no input-type, I need to add an tabindex="0" attribute to my SVG element (see Stackoverflow). However I never arrive in my event handler...

    svg.on('keydown', function(event) {... });

  2. So I tried listening to all keyboard events on my window, but I also never arrive in my event.

    $(window).on('keydown', function(evt) {...});

  3. Finally listening to all keyboard events on my document works:

    $(document).bind("keydown", function() {...});`

From this I 'assume' that the event propagation towards my config screen window is somewhere stopped by Node-RED?

I am now wondering if option 3 is an acceptable approach? Have not digged into it further, but I assume I have to start taking into account that my handler should always be removed correctly, to avoid duplicate processings.

Thanks !!!
Bart

Node-RED only blocks events if they match an assigned keyboard shortcut. Otherwise you wouldn't be able to type text into any thing.

So there must be some other reason for why your event listener isn't being triggered.

1 Like