Help with Multitouch

Dear experts,
I am using Matlab R2023a with PsychtoolboxVersion 3.0.19 - Flavor: beta - Corresponds to SVN Revision 13508 installed on a Surface Pro 6 Commercial Model 1796 i5 with Windows Windows 10 Pro.
I am not new to psychtoolbox, but I am new to record responses from touchscreens. I have searched for previous similar questions and tried to solve my problem by running the demos, but I am still not quite there. I would be very greatfull if you could help me.
I would like to create a sort of line bisection task, so I would like to display a line onscreen for unlimited time untill the patient touch it in the middle. However rather than just ask the patients to simply point (and touch the middle of the line) with one finger, I would like them to “grasp” the line, so by using two fingers, as if they are grasping a pen and measure the x and y of each of the two fingers (so that afterward I can measure the aperture of the fingers).
Below is part of the code that have the following two problems:

  1. the line is diplayed onscreen, but then the screen is refreshed , so it turns black and then the line is disaplyes again. How can I avoid the screen from flashing black?

  2. I would like the for loop across trials (different line lengths) to go on to the next trial soon after the patient has touched the screen (with the two fingers as described above), but at the moment it is going on only after keyboard press.
    I copy part of the code below.
    Resp=;
    for t=1:length(pix_linelength)
    % play sound
    [soundData freq ] = audioread(‘ding.wav’);
    PsychPortAudio(‘FillBuffer’, pahandle, soundData’);
    PsychPortAudio(‘Start’, pahandle, 1,0);
    WaitSecs(1)

    SetMouse(0, 0);
    [x,y]=GetMouse;

    tic

    % Get first touchscreen:
    dev = min(GetTouchDeviceIndices(, 1));
    info = GetTouchDeviceInfo(dev);
    % Create and start touch queue for window and device:
    TouchQueueCreate(w, dev);
    TouchQueueStart(dev);

    % blobcol tracks active touch points - and dying ones:
    blobcol = {};
    buttonstate = 0;
    blobmin = inf;

    % Main loop: Run until keypress:

    while ~KbCheck
    Screen(‘DrawLine’, w, [0 0 0], xmid-pix_linelength(t), ymid, xmid+pix_linelength(t), ymid, 10);
    Screen(‘Flip’,w);
    % Process all currently pending touch events:
    while TouchEventAvail(dev)
    % Process next touch event ‘evt’:
    evt = TouchEventGet(dev, w);

         % Touch blob id - Unique in the session at least as
         % long as the finger stays on the screen:
         id = evt.Keycode;
    
         % Keep the id's low, so we have to iterate over less blobcol slots
         % to save computation time:
         if isinf(blobmin)
             blobmin = id - 1;
         end
         id = id - blobmin;
    
         if evt.Type == 0
             % Not a touch point, but a button press or release on a
             % physical (or emulated) button associated with the touch device:
             buttonstate = evt.Pressed;
             continue;
         end
    
         if evt.Type == 1
             % Not really a touch point, but movement of the
             % simulated mouse cursor, driven by the primary
             % touch-point:
             Screen('DrawDots', w, [evt.MappedX; evt.MappedY], baseSize, [1,1,1], [], 1, 1);
             continue;
         end
    
         if evt.Type == 2
             % New touch point -> New blob!
             blobcol{id}.col = rand(3, 1);
             blobcol{id}.mul = 1.0;
             blobcol{id}.x = evt.MappedX;
             blobcol{id}.y = evt.MappedY;
             blobcol{id}.t = evt.Time;
             % Track time delta in msecs between touch point updates:
             blobcol{id}.dt = 0;
         end
    
     end
    

    end

    TouchQueueStop(dev);
    TouchQueueRelease(dev);

    %coord two fingers
    xfing1=blobcol{1}.x;
    yfing1=blobcol{1}.y;

    xfing2=blobcol{2}.x;
    yfing2=blobcol{2}.y;

    tr=toc;

    Resp=[Resp;pix_linelength(t) yfing1 yfing1 yfing2 yfing2 ]

    Screen(w,‘FillRect’,255);
    Screen(‘Flip’,w);
    WaitSecs(1)

end

Your approach is way insufficient to make this work in any robust way and clearly nobody feels like helping you for free.

I toyed around a bit with this idea you want to implement, and produced some sample script that you could use as a starting point for your experiment. This has taken myself a bit more than 1.5 hours, including testing on Ubuntu Linux 20.04.6-LTS and Windows 11 21H2 on my MS Surface Pro 6.

So if you want this help and sample code, quickly post your paid support authentication token to pay for the first 30 minutes out of 90 minutes (help PsychPaidSupportAndServices). You’d then have to buy another extra hour of support on top of that, following my instructions, but how much the extra hour costs depends on how old your current PTB membership license is - the one you hopefully own to get a good discount, otherwise you’d look at something like 500 Euros + sales tax.

-mario

No, thank you, I don’t have money to spend on this.
If I can sort it out myself, I will post the solution for free, in case other researchers find it useful.

Ok, fair enough. Obviously the problem is solvable, as I solved it already, but judging the current state of your code you’ll have a good amount of learning and work ahead of you.

Good luck,
-mario