# Keyboard input not working as intended online

**URL:** <https://discourse.psychopy.org/t/keyboard-input-not-working-as-intended-online/37123>\
**Category:** Online experiments\
**Tags:** text\
**Created:** [October 27, 2023, 8:47am UTC](https://discourse.psychopy.org/t/keyboard-input-not-working-as-intended-online/37123 "2023-10-27T08:47:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![smca64](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@smca64](https://discourse.psychopy.org/u/smca64)\
**Post date:** [October 27, 2023, 8:47am UTC](https://discourse.psychopy.org/t/keyboard-input-not-working-as-intended-online/37123/1 "2023-10-27T08:47:48Z")

</div>

URL of experiment: [practiceTask\_online [PsychoPy]](https://run.pavlovia.org/siobhanmca4/practicetask?session=test)

Description of the problem:  
I am trying to record the duration of time taken when participants imaging that they are copying a digit sequence with letters. Ideally, to begin responding, lctrl is pressed. To end the routine, lctrl or lshift is pressed again. It works on builder, but it freezes on the response screen online. I’ve followed the youtube tutorial by Jason Ozubko, and have tried various solutions I’ve found on the forum.

Here is the code for the beginning of the routine:

```auto
event.clearEvents('keyboard')
respKeys_imagery = [] 
key_press = 0
if expInfo['session'] == "baseline" or expInfo['session'] == "test" :
    continueRoutine = True 
else:
    continueRoutine = False

```

Every frame:

```auto
if keyResp1_imagery.keys: 
    respKeys_imagery.append(respKeys_imagery.keys)
    if(respKeys_imagery == 'lctrl'):
        thisExp.addData("imageryStartTime", t)
        event.clearEvents('keyboard')
    elif(respKeys_imagery == ['lctrl', 'lshift']): # have also tried ['lctrl', 'lctrl']
        thisExp.addData("imagerySubmitTime", t)
        continueRoutine = False 

```

I have also tried the following in every frame:

```auto
if keyResp1_imagery.keys:
    if len(keyResp1_imagery.keys) == 1:
        thisExp.addData("imageryStartTime", t)
        event.clearEvents('keyboard')
    elif len(keyResp1_imagery.keys) == 2:
        thisExp.addData("imagerySubmitTime", t)
        continueRoutine = False 

```

I have set event as outlined by the crib sheet.

When I add two keyboard components, with lshift set to end the trial in the second component, the trial proceeds but I am able to proceed without pressing the first button to indicate starting the imagery, but I can’t figure out how to start the second keyboard on the condition that the first keyboard component has been completed (i.e., lctrl has been pressed).

Any help would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![smca64](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@smca64](https://discourse.psychopy.org/u/smca64)\
**Post date:** [November 1, 2023, 9:24am UTC](https://discourse.psychopy.org/t/keyboard-input-not-working-as-intended-online/37123/2 "2023-11-01T09:24:51Z")

</div>

I have changed from using CTRL to using another key and the issue appears to be sorted
