Textinput - problems with num pad

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10):
PsychoPy version 2020.2.4
**Standard Standalone? (y)
Hallo!
After having similar problems with the textbox as Editable textbox still showing through after update
I searched for an alternative solution which works fine for me
textinput - https://github.com/jacanterbury/PsychoPy-snippets/tree/master/textInput

However, I also have the problem that num pad numbers are presented differently e.g. when I press ‘1’ then ‘num_1’ is shown on the screen.
I tried to extend the code of jacanterbury by inserting the following line in the each frame part:

elif ‘num_’ in keys:
text.text = text.text.replace(‘num_’, ’ ')

Unfortunately, this does not work (I tried also several other combinations). Has anyone an idea what is wrong with this code?

Thank you very much!

In what way does it not work? Does the replacement just not happen or does it throw an error?

Hi TParsons! The replacement does not happen.

What happens if you put a print statement inside that if gate? Does it print?

I suspect it might be that it’s looking for an item in keys whose value is in its entirety num_, when what you want to know is whether num_ is in any string within keys. You can use this instead to ensure that behaviour:

elif any('num_' in key for key in keys): # if any key in keys contains 'num_'

…or, if you prefer, you could treat keys as one long string:

elif 'num_' in "".join(keys):

Thank you very much for your reply!
I implemented your code, but it worked only partly when I put it as a separate if statement.

if any(‘num_’ in key for key in keys):
text.text = text.text.replace(‘num_’, ‘’)

When I now use the numpad then I see the actual pressed number as “num_” e.g. “num_1” but the strange thing is that when I press another number e.g. “num_2” on the num pad then the first number “num_1” is converted to “1”. On the screen is see the following “1num_2”. This continues further e.g. “1234num_5”. Hope my outline is understandable. Do you have an idea of how to convert also the actual input?

Thank you very much!