How to discriminate key press sources?

Hi all,

I have a textarea.
When it’s focused, I would like all the key presses to go there,
when it’s not focused, I would like to respond to key presses and send messages.

An example would be the spacebar, when the textarea is focused, it should act as normal,
if the textarea is not focused, I would send a custom message.

Is there any library to do that, or what’s the best way to achieve that?

Thank you
Cheers!

1 Like

Here is an Ellie that maybe has what you are looking for:

https://ellie-app.com/q7sc2PSvPSra1

This all just standard library functionality.

By default a focused Textarea will receive all the key commands, so you don’t need to do anything in that state. It is when the Textarea is not focused you will want to capture the keys. Correct?

Correct.

So the idea is to keep the focus state in the model and act accordingly.

Thank you,
cheers!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.