Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Simultaneous mouse and keyboard listening?

Hi there. I'm pretty sure this is simple enough using the right code but I'm kinda new to Python and I haven't been able to set this up in the GUI.

I am doing a task where the subject estimates the position of a number in the number line, by touching first at zero and then at the target position. After doing that, by pressing the spacebar they get a feedback with their response.

My problem is that the mouse is only listening for the first click (target click. The touch zero is alright) and then the keyboard element starts listening, disabling the mouse response element, thus disabling the possibility to update the "final answer" so to speak.

I feel like the solution involves combining both within an inline script, but I haven't fully grasped how the get_key/mouseclick functions work.

Comments

  • edited December 14

    Hi @churrundo

    I think the solution here is indeed to have the mouse and keyboard handled together in a loop that only breaks when the spacebar is pressed.

    Maybe one way to do that with an inline script would be to create mouse and keyboard objects, and directly checking for mouse and keyboard input inside a 'while' loop with really short timeout durations. This way, it almost feels like both are "listening" at the same time, until the spacebar is pressed. I linked the relevant documentation so that you can better grasp how each function works.

    If you’d prefer to avoid inline scripting, I also put together a minimal GUI-based example that should work in a similar way, using coroutines.

    Let me know if that helps!

    Claire

  • I thought of using coroutines but it was too slow. The while loop was exactly it, thanks!

Sign In or Register to comment.