Howdy, Stranger!

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

Supported by

[open] Count key response

edited November 2014 in OpenSesame

Hi everybody. I'm having one little trouble with my experiment.

I'm collecting duration of specific key press (e.g. how long did participant press key A and key L) and I'm using inline script for that (psychopy backend, pyglet key). Now, I would like to collect sum of all key presses of these two keys (e.g. how many time did participant pressed key A, key L and both keys).

Inline script goes like this: https://gist.github.com/neklektyk/4b48ea0241e77644d855

I know that this is silly question, but I can't find anything in pyglet key doc. Do you guys have any idea?

Cheers!

Comments

  • edited 6:16AM

    Hi,

    So if I understand correctly what you're still missing a counter, i.e. you want to count how many times each key is pressed. Is that correct? I'm not very familiar with the inner workings of pyglet, but it looks like you'll have to implement some logic yourself to keep track of when a key state changes, and increment your counters accordingly. Something like:

    if response[[key.A] and not previous_response[key.A]:
        counter_A += 1
    

    Does that make sense? Looking at the complexity of your script you're not a Python newby, so I imagine this is feasible. (But not terribly convenient.)

    Hope this helps!

    Sebastiaan

  • edited 6:16AM

    Hi Sebastian.

    Yes, that's the little thing I'd like to count. I'll try to incororate these few lines of code into script, which is made by friend of mine, who is coding magician :)

    Beside this, I spotted one big problem: the script is not logging all the events (e.g. not all key press/release). In some number of cases, events are not even logged, like I didn't pressed/released any of keys. Do you have any idea what can be the problem? Maybe pyglet key?

    Cheers!

  • edited 6:16AM

    Yes, I see. You're setting the experimental variables after the loop. In other words, you're only logging the final state of the response variables. If you want to log every key press/ release, you would have to do this during the response collection loop. See what I mean?

    The easiest way to do this would be to write a message to the log file whenever something important happens. Just like you're printing stuff to the debug window now. Like so:

    self.log('pustio a %s' % time_a_only_pressed)
    

    If you do this, you will get an event-based logfile, which is very different from (and incompatible with) the spreadsheet logfile that the logger item will create for you. So that may be tricky, if you're not used to that kind of data. If you want to stick to a spreadsheet format, you'll have to decide first exactly how you want to organize your data. I.e. which columns do you want to have, and what kind of info should they contain?

Sign In or Register to comment.