Psychtoolbox version of waitforbuttonpress

I was wondering if anyone knew of a psychtoolbox version of
waitforbuttonpress. The function just pauses the program until a mouse
button is clicked. So far, I have discovered ASK (which displays text
in the top right corner, which I don't want) and getClicks (which
pauses for a little while even after you click because its waiting to
count additional clicks). I'm currently using getClicks, but I don't
want to additional pause if there is a function that will do exactly
what waitforbuttonpress does for figures. Thanks!

Jessica

Brandeis University
You can use GetMouse to check for a button press, but you have to
check it repeatedly in a loop. I use the below function to wait for a
mouse click in OS. It first waits until the mouse button is released
(in case it's still down from a previous response), then waits for it
to get pressed again. It's pretty minimalist, and doesn't return the
mouse position, keys pressed, or any timing information.

function MouseWait

[x, y, button] = GetMouse;
while any(button)
[x, y, button] = GetMouse;
end
while ~any(button)
[x, y, button] = GetMouse;
end


David

On 7/29/05, sabredanse <jmaryott@...> wrote:
> I was wondering if anyone knew of a psychtoolbox version of
> waitforbuttonpress. The function just pauses the program until a mouse
> button is clicked. So far, I have discovered ASK (which displays text
> in the top right corner, which I don't want) and getClicks (which
> pauses for a little while even after you click because its waiting to
> count additional clicks). I'm currently using getClicks, but I don't
> want to additional pause if there is a function that will do exactly
> what waitforbuttonpress does for figures. Thanks!
>
> Jessica
>
> Brandeis University

--
David Fencsik, Ph.D.
Research Fellow

Visual Attention Laboratory
Brigham and Women's Hospital
64 Sidney St., Suite 170
Cambridge, MA 02139

Phone: 617-768-8812
Email: fencsik@...
Web: http://search.bwh.harvard.edu/
Try waitforMouse, on my website.

http://csclab.ucsd.edu/~alan/vision/matlab_code/

sabredanse wrote:
> I was wondering if anyone knew of a psychtoolbox version of
> waitforbuttonpress. The function just pauses the program until a mouse
> button is clicked. So far, I have discovered ASK (which displays text
> in the top right corner, which I don't want) and getClicks (which
> pauses for a little while even after you click because its waiting to
> count additional clicks). I'm currently using getClicks, but I don't
> want to additional pause if there is a function that will do exactly
> what waitforbuttonpress does for figures. Thanks!
>
> Jessica
>
> Brandeis University
>
>
>
>
> Post your message to: psychtoolbox@yahoogroups.com
> Please indicate OS9, OSX, or WIN version, and include your full name.
> Denis Pelli, David Brainard, and Allen Ingling.
> http://psychtoolbox.org
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>
Thanks, this will help,

Jessica

--- In psychtoolbox@yahoogroups.com, David Fencsik <fencsik@g...> wrote:
> You can use GetMouse to check for a button press, but you have to
> check it repeatedly in a loop. I use the below function to wait for a
> mouse click in OS. It first waits until the mouse button is released
> (in case it's still down from a previous response), then waits for it
> to get pressed again. It's pretty minimalist, and doesn't return the
> mouse position, keys pressed, or any timing information.
>
> function MouseWait
>
> [x, y, button] = GetMouse;
> while any(button)
> [x, y, button] = GetMouse;
> end
> while ~any(button)
> [x, y, button] = GetMouse;
> end
>
>
> David
>
> On 7/29/05, sabredanse <jmaryott@b...> wrote:
> > I was wondering if anyone knew of a psychtoolbox version of
> > waitforbuttonpress. The function just pauses the program until a mouse
> > button is clicked. So far, I have discovered ASK (which displays text
> > in the top right corner, which I don't want) and getClicks (which
> > pauses for a little while even after you click because its waiting to
> > count additional clicks). I'm currently using getClicks, but I don't
> > want to additional pause if there is a function that will do exactly
> > what waitforbuttonpress does for figures. Thanks!
> >
> > Jessica
> >
> > Brandeis University
>
> --
> David Fencsik, Ph.D.
> Research Fellow
>
> Visual Attention Laboratory
> Brigham and Women's Hospital
> 64 Sidney St., Suite 170
> Cambridge, MA 02139
>
> Phone: 617-768-8812
> Email: fencsik@g...
> Web: http://search.bwh.harvard.edu/
Thank you - I'll be able to use a slimmed down version of this to do
exactly what I need.

Jessica

--- In psychtoolbox@yahoogroups.com, Alan Robinson <alanAtHome@h...>
wrote:
> Try waitforMouse, on my website.
>
> http://csclab.ucsd.edu/~alan/vision/matlab_code/
>
> sabredanse wrote:
> > I was wondering if anyone knew of a psychtoolbox version of
> > waitforbuttonpress. The function just pauses the program until a mouse
> > button is clicked. So far, I have discovered ASK (which displays text
> > in the top right corner, which I don't want) and getClicks (which
> > pauses for a little while even after you click because its waiting to
> > count additional clicks). I'm currently using getClicks, but I don't
> > want to additional pause if there is a function that will do exactly
> > what waitforbuttonpress does for figures. Thanks!
> >
> > Jessica
> >
> > Brandeis University
> >
> >
> >
> >
> > Post your message to: psychtoolbox@yahoogroups.com
> > Please indicate OS9, OSX, or WIN version, and include your full name.
> > Denis Pelli, David Brainard, and Allen Ingling.
> > http://psychtoolbox.org
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >
> >
Hi there,

I have written code that simply flashes different ovals on the screen. If I do the ovals in color, frames are dropped (consistently 60 frames in the below demo), but if I do it in gray scale, it works fine (consistently drops 0 frames). I assume I am not using color optimally, but can't quite figure it out. My code for the colored circles is below. Does anyone have any advice?

thanks a bunch,
Maria Mckinley


% MailListDemo
% adapted from Psychtoolbox MovieDemo2
% show on main screen
whichScreen=0;
pixelSizes=Screen(whichScreen,'PixelSizes');
nFrames=round(.5*FrameRate(whichScreen));
priorityLevel=MaxPriority(whichScreen,'GetSecs','WaitBlanking');

max(pixelSizes)
% Open screen. Do this before opening the
% offscreen windows so you can align offscreen
[window,windowRect]=Screen(whichScreen,'OpenWindow',0,[],max(pixelSizes));
% Setting clut seems to make no difference.
onClut=(0:255)'*[1 1 1];
Screen(window,'SetClut',onClut);


%%% THIS CODE IS JUST TO GET THE COORDINATES FOR THE RECTANGLE TO USE FOR THE OVAL
% adapted from shadlendots
% viewing width of monitor (cm)
mon_horizontal_cm = 34;
% distance from the center of the subject's eyes to the monitor (cm)
view_dist_cm = 60;
pixPerDeg = windowRect(3) * ...
(1 ./ (2 * atan2(mon_horizontal_cm / 2, view_dist_cm))) * ...
pi/180;
half_width = windowRect(3)/2;
half_height = windowRect(4)/2;
ppd = pixPerDeg/10;
% the first circle will have diameter 30, centered
xyd = [0 0 30];
d_ppd = xyd(:, 3) * ppd;
x0 = half_width + xyd(:, 1) * ppd - 0.5 * d_ppd;
y0 = half_height - xyd(:, 2) * ppd - 0.5 * d_ppd;
destRect = [x0 y0 (x0 + d_ppd) (y0 + d_ppd)];
% the second circle will have diameter 30, to the left and up of the center
xyd = [10 10 30];
d_ppd = xyd(:, 3) * ppd;
x0 = half_width + xyd(:, 1) * ppd - 0.5 * d_ppd;
y0 = half_height - xyd(:, 2) * ppd - 0.5 * d_ppd;
destRect2 = [x0 y0 (x0 + d_ppd) (y0 + d_ppd)];


% Put images into offscreen memory. When we open an offscreen
% window we specify which on-screen window it should be
% aligned with, for fast copying.

ow1=Screen(window,'OpenOffscreenWindow',0,windowRect);
Screen(ow1,'FillOval', [255 0 0], destRect);

ow2=Screen(window,'OpenOffscreenWindow',0,windowRect);
Screen(ow2,'FillOval', [0 0 255], destRect2);

% Set up string for Rush. You can make this as long as you like.
% The initial call to WaitBlanking synchronizes the program with the display blanking.
missed1=zeros(nFrames,1);
missed2=zeros(nFrames,1);
GetSecs; % Preload all functions.

loop={
'Screen(window,''WaitBlanking'');'
'startTime=GetSecs;'
'for i=1:nFrames;'
'Screen(''CopyWindow'', ow1, window,windowRect,windowRect,''srcCopy'');'
'missed1(i)=Screen(window,''WaitBlanking'');'
'Screen(''CopyWindow'', ow2, window,windowRect,windowRect,''srcCopy'');'
'missed2(i)=Screen(window,''WaitBlanking'');'
'end;'
'finishTime=GetSecs;'
};

% Show the movie. The Rushed code does the timing.
HideCursor;
Screen('Screens');GetSecs; % Make sure all Rushed functions are in memory.
Rush(loop,priorityLevel);
ShowCursor;

% Close up
Screen('CloseAll');

% Print results
fprintf('MovieDemo4\n');
s=sprintf('Movie is %.0f Hz.',FrameRate(whichScreen));
s=sprintf('%s Copied %.0f images/sec.',s,2*nFrames/(finishTime-startTime));
s=sprintf('%s Missed %g frames.',s,sum(sum([missed1 missed2])));
fprintf('%s\n',WrapString(s));

RestoreScreen(whichScreen); % As of 7/31/02, FrameRate may leave CLUT in strange state.
On Fri, 5 Aug 2005, David Fencsik wrote:

> Maria,
>
> In your sample code, the ovals are drawn to off-screen windows that
> are the same size as the on-screen window. This means that you are
> copying a whole lot of unnecessary bytes every time a stimulus is
> copied to the screen. Try making the off-screen stimulus windows as
> small as possible (i.e., the max radius of the ovals).
>
> David
>

Hi David,

Thanks for the advice. The reason I did that is because I was having problems with the rectangles showing up when stimuli overlapped, if I didn't. Using the large off-screen window did not cause a timing problem in the black and white version, so I thought it should work with the color too. I really don't understand why it wouldn't, but if you have another idea of how to do this without the rectangles showing up, that would be great. I'm including some code that demonstrates what I mean about the rectangles.

Tyi, this code will eventually be incorporated in a gui, in which the user is able to make the two circles any size, and put them anywhere on the screen (including one on top of the other, as in this demo). Sometimes they will both be shown at the same time, and sometimes just one at a time.

thanks,
Maria

% MailListDemo2
% adapted from Psychtoolbox MovieDemo2
% show on main screen
whichScreen=0;
nFrames=round(0.5*FrameRate(whichScreen));
priorityLevel=MaxPriority(whichScreen,'GetSecs','WaitBlanking');

% Open screen. Do this before opening the
% offscreen windows so you can align offscreen
% window memory to onscreen for faster copying.
[window,windowRect]=Screen(whichScreen,'OpenWindow',0,[],8);

onClut=(0:255)'*[1 1 1];
Screen(window,'SetClut',onClut);
imageRect=SetRect(0,0,200,200);
imageRect2=SetRect(0,0,300,300);
destRect=CenterRect(imageRect,windowRect);
destRect2=CenterRect(imageRect2,windowRect);
% Put images into offscreen memory. When we open an offscreen
% window we specify which on-screen window it should be
% aligned with, for fast copying.

ow1=Screen(window,'OpenOffscreenWindow',0,imageRect,8);
Screen(ow1,'FillOval', 100, imageRect);

ow2=Screen(window,'OpenOffscreenWindow',0,imageRect2,8);
Screen(ow2,'FillOval', 255, imageRect2);

% Set up string for Rush. You can make this as long as you like.
% The initial call to WaitBlanking synchronizes the program with the display blanking.
missed1=zeros(nFrames,1);
missed2=zeros(nFrames,1);
GetSecs;
% Preload all functions.
loop={
'Screen(window,''WaitBlanking'');'
'startTime=GetSecs;'
'for i=1:nFrames;'
'Screen(''CopyWindow'', ow1, window,imageRect,destRect,''srcCopy'');'
'missed1(i)=Screen(window,''WaitBlanking'');'
'Screen(''CopyWindow'', ow2, window,imageRect2,destRect2,''srcCopy'');'
'missed2(i)=Screen(window,''WaitBlanking'');'
'end;'
'finishTime=GetSecs;'
};

% Show the movie. The Rushed code does the timing.
HideCursor;
Screen('Screens');GetSecs; % Make sure all Rushed functions are in memory.
Rush(loop,priorityLevel);
ShowCursor;

% Close up
Screen('CloseAll');

% Print results
fprintf('MovieDemo3\n');
s=sprintf('Movie is %.0f Hz.',FrameRate(whichScreen));
s=sprintf('%s Copied %.0f images/sec.',s,2*nFrames/(finishTime-startTime));
s=sprintf('%s Missed %g frames.',s,sum(sum([missed1 missed2])));
fprintf('%s\n',WrapString(s));

RestoreScreen(whichScreen);
% As of 7/31/02, FrameRate may leave CLUT in strange state.
Hi Maria,

I think the reason you only observe dropped frames in color and not in
black and white is that the computer has to copy three times as much
information in color relative to b/w. There is only one byte per
pixel in b/w vs. three bytes per pixel for color (one byte each for
red, green, and blue levels).

As for the visible rectangles, try specifying 'transparent' instead of
'srcCopy' as the last argument to Screen('CopyWindow'), and make sure
your ovals are drawn on a white background. To make sure they have a
white background, open your offsreen windows like this:

ow1=Screen(window,'OpenOffscreenWindow',[],imageRect);

The 'transparent' argument instructs 'CopyWindow' to skip any white
pixels in the source window. Of course, it will also skip any
white-colored pixels within the oval, so you need to draw them in
off-white. I draw white stimuli using a color value of 254 instead of
255.

Incidentally, does anybody have a better solution to transparently
drawing white stimuli? Is there a method for specifying a different
color to use as the transparent one?

Hope that helps.

David


--
David Fencsik, Ph.D.
Research Fellow

Visual Attention Laboratory
Brigham and Women's Hospital
64 Sidney St., Suite 170
Cambridge, MA 02139

Phone: 617-768-8812
Email: fencsik@...
Web: http://search.bwh.harvard.edu/


On 8/5/05, Maria McKinley <parody@...> wrote:
>
> Hi David,
>
> Thanks for the advice. The reason I did that is because I was having problems with the rectangles showing up when stimuli overlapped, if I didn't. Using the large off-screen window did not cause a timing problem in the black and white version, so I thought it should work with the color too. I really don't understand why it wouldn't, but if you have another idea of how to do this without the rectangles showing up, that would be great. I'm including some code that demonstrates what I mean about the rectangles.
>
> Tyi, this code will eventually be incorporated in a gui, in which the user is able to make the two circles any size, and put them anywhere on the screen (including one on top of the other, as in this demo). Sometimes they will both be shown at the same time, and sometimes just one at a time.
>
> thanks,
> Maria
Thanks David,

Silly me, I was thinking you still had to do 3 matrices, but of course
they would be the same matrix, so would actually only be one. Should
have thought that one through more before I asked. I guess I had
assumed that it would handle these matrices more intelligently (ie, most
of my screen is black, so

Definitely making progress, but this introduces a new question. The way
I was doing things previously, if I wanted to show a target that was up
on the previous screen, I just made an offscreen window that has both
targets. Now I don't know how to do this. Trying to make an image
rectangle that is big enough for both targets seems silly (and if they
are in opposite corners, is the same as copying the whole screen and
will be just as slow), but trying to copy multiple, sometimes
overlapping, windows to one screen seems to introduce weird visual
glitches, and I can't make it do exactly what I want anyway.

Maybe I shouldn't be trying to make a movie at all. I think I will test
to see how fast filloval is when drawing directly to the screen.

If anyone has any further ideas, I'm all ears...

cheers,
maria

David Fencsik wrote:
> Hi Maria,
>
> I think the reason you only observe dropped frames in color and not in
> black and white is that the computer has to copy three times as much
> information in color relative to b/w. There is only one byte per
> pixel in b/w vs. three bytes per pixel for color (one byte each for
> red, green, and blue levels).
>
> As for the visible rectangles, try specifying 'transparent' instead of
> 'srcCopy' as the last argument to Screen('CopyWindow'), and make sure
> your ovals are drawn on a white background. To make sure they have a
> white background, open your offsreen windows like this:
>
> ow1=Screen(window,'OpenOffscreenWindow',[],imageRect);
>
> The 'transparent' argument instructs 'CopyWindow' to skip any white
> pixels in the source window. Of course, it will also skip any
> white-colored pixels within the oval, so you need to draw them in
> off-white. I draw white stimuli using a color value of 254 instead of
> 255.
>
> Incidentally, does anybody have a better solution to transparently
> drawing white stimuli? Is there a method for specifying a different
> color to use as the transparent one?
>
> Hope that helps.
>
> David
>
>