Borrar filtros
Borrar filtros

simulate a keypress in a loop

5 visualizaciones (últimos 30 días)
HYZ
HYZ el 18 de Oct. de 2022
Respondida: Saffan el 30 de Ag. de 2023
Hi,
I want to simulate a keypress to trigger a new trial on Psychopy. the first keypress did work to trigger but the subsequent keypress did not work. the code below worked for other windows like notepad etc but not on Psychopy. could anyone suggest? Thanks.
import java.awt.Robot;
import java.awt.event.*;
Sim=Robot;
count = 0;
Sim.mouseMove(0, 0);
pause (3)
Sim.mouseMove(520, 520);
Sim.mousePress(InputEvent.BUTTON2_MASK);
pause (0.5)
Sim.mouseRelease(InputEvent.BUTTON2_MASK);
while count < 5
Sim.keyPress(KeyEvent.VK_ENTER);
count = count + 1;
display (count)
end
  1 comentario
HYZ
HYZ el 18 de Oct. de 2022
maybe making the psychopy window active between each trial might solve. But I don't know how to make the psychopy window active.

Iniciar sesión para comentar.

Respuestas (1)

Saffan
Saffan el 30 de Ag. de 2023
Hi,
Instead of simulating middle mouse button press, that is, “InputEvent.BUTTON2_MASK”, you can simulate the left mouse button press, that is, “InputEvent.BUTTON1_MASK”. Alternatively, you can activate “psychopy” window in each iteration using the code snippet as follows:
% Get all the active windows
allWindows = java.awt.Window.getWindows();
% Select the desired window
selectedWindow = allWindows(1);
% Set the selected window as active
selectedWindow.toFront();

Categorías

Más información sobre Timing and presenting 2D and 3D stimuli en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by