Howdy, Stranger!

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

Supported by

Looking for help with inline script executing ACE setup

Hi all,
I'm trying to create an "Action-sentence-compatibility" experiment. This requires the participant to hold down a key while reading a sentence and then releasing the key to press another key to categorize the sentence. This means I need to measure "keyrelease". I found an old thread dealing with this (http://forum.cogsci.nl/index.php?p=/discussion/206/solved-key-realease), so I copied the code in that thread and it works great.
The issue is that I want to add a keypress after the keyrelease code (to capture the 2nd key pressed by the participant to categorize the sentence). I want to do this within the same inline code script (I suspect that will offer better timing reliability).
I've tried a few different things, but my computer keeps freezing, which I assume means my "while loop" is not evaluating properly.
Here's my modified code - any help would be very welcome. It works fine until the 2nd keypress part at the end (if I remove that it works perfectly).
(On a related topic, does anyone know what kind of response-time variability this kind of code will deliver?)

from psychopy import visual, core
from pyglet.window import key

response = key.KeyStateHandler()
self.experiment.window.winHandle.push_handlers(response)

fileChain = r"D:\\Users\\ms16492\\Documents\\OpenSesameScripts\\ACE_Arabic\\"

var.trialCounter = i
pressDuration = 0

win = self.experiment.window
time = core.Clock()

#The sentence to be displayed.
sentence = fileChain + "arab" + str(i) + "cropped.png"

#The prompt before the sentence.
testString = "Hold down the g key, hit the a key if the sentence was meaningful, and the l key if it was meaningless."

#message between trials.
intermediateString = "Get ready for the next trial"

press = visual.TextStim(win, pos=(0,0), color = "black", text=testString + str(i) + " " + str(pressDuration))
release = visual.ImageStim(win, pos=(0,0), image=sentence)
intermediate = visual.TextStim(win, pos=(0,0), color = "black", text=intermediateString)

    # key not pressed
while not response[key.G]:
    press.draw()
    win.flip()
    t1 = time.getTime() # key pressed! (first timestamp)
    #Make this variable generally accessible:
    var.t_1 = t1
    core.wait(0.1)

while response[key.G]:
    release.draw()
    win.flip()

t2 = time.getTime() # key released! (second timestamp)
#Make this variable generally accessible:
var.t_2 = t2

pressDuration = t2-t1 # compute the key pressing time
#Make this variable generally accessible:
var.press_duration = pressDuration

core.wait(0.1)


#TRYING TO COLLECT A SECOND KEYPRESS HERE.
response2 = key.KeyStateHandler()
self.experiment.window.winHandle.push_handlers(response2)

while not response2[key.A]:
    intermediate.draw()
    win.flip
`

Comments

  • Hi,

    If you just want to get a keypress response, you could use the code below. It uses Opensesame instead of going directly into PsychoPy. I don't think it matters, but make sure that it works how you expect it to. Of course you could do this also with PsychoPy, but I don't know the commands by heart...

    # create a keyboard
    kb = keyboard()
    # wait for keypress and allow a response time of 5000 seconds
    var.key,var.time = kb.get_key(timeout=5000)
    
    # var.time is now only a time stamp. If you want it to be a response time, you need to subtract the start time (not sure which is the one you want to use, so this is up to you
    
    var.response_time_categorization = var.time - <Insert start time>
    

    Hope this helps.

    Eduard

    Buy Me A Coffee

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games