필터 지우기
필터 지우기

simulate a keypress in a loop

조회 수: 5 (최근 30일)
HYZ
HYZ 2022년 10월 18일
답변: Saffan 2023년 8월 30일
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
HYZ
HYZ 2022년 10월 18일
maybe making the psychopy window active between each trial might solve. But I don't know how to make the psychopy window active.

댓글을 달려면 로그인하십시오.

답변 (1개)

Saffan
Saffan 2023년 8월 30일
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();

카테고리

Help CenterFile Exchange에서 Timing and presenting 2D and 3D stimuli에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by