Effacer les filtres
Effacer les filtres

simulate a keypress in a loop

5 vues (au cours des 30 derniers jours)
HYZ
HYZ le 18 Oct 2022
Réponse apportée : Saffan le 30 Août 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 commentaire
HYZ
HYZ le 18 Oct 2022
maybe making the psychopy window active between each trial might solve. But I don't know how to make the psychopy window active.

Connectez-vous pour commenter.

Réponses (1)

Saffan
Saffan le 30 Août 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();

Catégories

En savoir plus sur Timing and presenting 2D and 3D stimuli dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by