Howdy, Stranger!

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

Supported by

Press and hold key for set duration before continuing sequence

Hi there,

I'm new to OpenSesame and Python but I've been asking some progress with a few threads and the key release is working fine but I'm having some trouble setting a 'press and hold' response that is needed to start the sequence.

The experiment is quite simple:

  1. Participant has to press and hold a key for 1000ms
  2. Three discs appear on the screen
  3. One of the disk turns green, release the button press, and make a reaching motion to touch the location on the touchscreen

I am struggling to set the press and hold response. I've searched the topics from a similar topic and I was trying to figure out a way to adapt this inline from an earlier topic:

I just don't have enough knowledge of python to know how to go about it.

Any help is much appreciated.

Comments

  • Hi,

    The problem with your script is the indentation, i.e. the number of tabs that precede each line. The break statement should be intended one step down, so that it's not in the else block. Does that make sense? Like this:

    import pygame
    
    while True:
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                break
        else:
            continue
        break
    

    An equivalent code that is perhaps easier to read would be:

    import pygame
    
    while not any(event.type == pygame.KEYDOWN for event in pygame.event.get()):
        pass
    

    To learn a bit more about loops, check out this video:

    Cheers!
    Sebastiaan

  • That makes perfect sense, Sebastiaan. The video was quite helpful but I am still struggling to implement the hold component for this task.

    I can get an approximation by setting the duration of a sketchpad for 3995ms (we've increased the length of the press). However, I need to be able to reset the trial if the key is released early. I need the key release time before a reaching response is performed to the target on a touchscreen.

    I have been trying to adapt some of your code from an earlier post for measuring key press durations within a while loop plus an else loop, combined with another post that used items.execute() command to break from a component if response incorrect. I can't quite get it to work and I think I may have the logic/structure of the loop confused or maybe I need a coroutine?

    I have included a screenshot of the structure of the experiment and the code element I have been working on.

    My intention was something along these lines:
    While a key is held down for less than 4 seconds, draw a canvas with some text and a prompt image. Get the time and update key_down_time. Then break/continue with the next component.

    Else: if the key is released before the 4s time limit then reduce the trial_loop count by 1 and execute the reset_loop.

    Begin trial again

    Apologies for the long-winded nature of my query. Any help is much appreciated.

    Josh

  • edited January 2018

    Hi there,

    I have got the task working in terms of basic functionality. Ideally, it would be good if I could implement a coroutine that exits if a key release is made during the presentation of two sequential sketchpads to catch early releases.

    I have tried to adapt the information about creating custom coroutines that terminate with a response but it does not register for the key release - I suppose because the return does not include a 'key release response' component. I am not sure how to implement that.

    At the minute I have the following in place:

    1. inline: defining the key release generator
    2. coroutines: sketchpad hold (3995ms)
    3. coroutines: sketchpad: show three stimulus positions (variable delay; ~750 - 2500ms)

    If there's no key release by the end of coroutine, coroutine should exit to continue sequence. If there is a key release during coroutine then it should exit to a 'Too early' feedback screen and reset or repeat that trial.

    An example, or suggestions for how to proceed would be greatly appreciated.

    Josh

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