I'm trying to create a textfield that only allows certain keys for input and does not require focus for input.

The way I would like to do this is have my program listen for certain keypresses and ignore all other keypresses. I don't know how to listen for keypresses though.

A great example of what I'm trying to do is in the calculator app where instead of using the on-screen keys, you can also press the physical number keys and the corresponding numbers will be displayed on screen (without the blinking text cursor). When you press letters though, nothing happens. This is exactly what I'm trying to do.

If somebody could help me out with this I would be extremely grateful.


Thanks,
TJ