Is it possible to check if the user presses space or any key at all while being focused on a text input?

Is it possible to check if the user presses space or any key at all while being focused on a text input?

Basically like a search bar so when there’s text in the input it allows you to press the return key to UNfocus the text input and store the value in a variable or what ever you’d like to do after that