Using keyboard response to get reaction time

Hello everyone!

I hope this question does not seem unnecessary to you, but I’m struggling a bit with incorporating a keyboard response into my code. I’m working with the coding view, but I also used the builder to create a keyboard response so I could include the exported code in my code. However, this did not work.
I want the keyboard response only for the target items (whenever a certain picture appears, the subjects have to press a key) and it is not supposed to affect the presentation of the stimuli. The only thing it is there for is that subjects should press a key when they see the target item and this reaction time will be recorded and logged. I wondered if someone has already used this kind of keyboard response (builder or coder is not relevant as I could recreate things with the builder and add it to my code) and could give me some advice on how to do this. Currently, my keyboard response does not reliably measure reaction times, stops the stimulus presentation or does not work at all. I could really need some advice on which elements to incorporate where.
I am really sorry if this seems unnecessary to ask for, but the other discussion did not help me solve this issue.

The screenshot shows the code snippet I added to my code in the running routine of the stimulus presentation (I defined key_resp earlier in the code). Is this the right approach? At the moment this does not work as there is an undefined variable that I have to figure out, but even if it works I am afraid it will stop the flow and will record reaction time all the time and not just for the target item.

Anyway, any help is tremendously appreciated! Thank you very much!

Nevermind, solved the issue!