[visionegg] Re: vision egg question

  • From: Dav Clark <dav@xxxxxxxxxxxx>
  • To: visionegg@xxxxxxxxxxxxx
  • Date: Tue, 18 Aug 2009 22:42:03 -0700

Another potential cause of missing keypresses is if you are using the Presentation class. This will actually check the pygame event queue each cycle, and can stomp on any keys you might be looking for.


It helped when I modified my instantiation of presentation like so:

        self.presentation = Presentation(viewports=[viewport],
                check_events=False)

Cheers,
Dav

On Aug 18, 2009, at 5:31 PM, Dave Bissig wrote:

Just my two cents:
(1) instead of break, you can raise SystemExit when hitting ESC. ... if memory serves, this works in OSX. (see below) (dunno how equivalent the two are, but raise SystemExit def. works).

(2) I've found that defining the escape key works best if you can build it into a preexisting pygame.event.get(), as shown here (where you're waiting for the user to mousedown OR press the escape key):

########################################
def WaitAround():
    waiting=0
    while waiting != 1:
        for event in pygame.event.get():
            if event.type == pygame.locals.MOUSEBUTTONDOWN:
                xpos,ypos = pygame.mouse.get_pos()
CheckMousePosition(xpos,ypos) ## ...do something based on where mousedown was... waiting=1 ## on mousedown, this kicks you back to the main loop, where viewports are redrawn, etc.
            elif event.type == pygame.locals.KEYDOWN:
                if event.key == pygame.locals.K_ESCAPE:
                    screen.close()
                    screen.close()
## out_file.close() ## in case you were writing a text file or some such
                    raise SystemExit
########################################

(3) in case anyone forgot/didn't know, the keyboard constants (e.g."K_ESCAPE") are documented here:
     http://www.pygame.org/docs/ref/key.html

Hope this helps,
Dave Bissig
WSU-SOM

~ ~ ~ ~ ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




On Tue, Aug 18, 2009 at 1:48 PM, Rachel Denison <rdenison@xxxxxxxxxxxx> wrote: Thanks for the help, Dav and Ariel! I was also surprised that the vision egg display didn't capture focus, even in full screen mode. I still have to click somewhere on the screen with the (invisible) cursor before the program responds to key presses. Is there some kind of setting that I'm missing?

I'm using OSX, and cmd-opt-escape works fine for exiting the program. This should work for my purposes, but it would be nice if there were a more graceful way. I tried Ariel's escape key definition idea. It hasn't worked so far for me, but I may just need to play around with it a little more.

Thanks again,

Rachel



On Tue, Aug 18, 2009 at 8:37 AM, Ariel Rokem <arokem@xxxxxxxxxxxx> wrote:
Hi Rachel,

another way to allow exiting the program while it is running, is
defining an escape key (I just use the Escape key :D) and then polling
the keyboard every given (rather short) time. Then, if the escape key
is pressed when you reach the polling point, break out of your trial
loop and terminate the program.

Something like this should do it:

for event in pygame.event.get(pygame.KEYDOWN):
   if event.key == pygame.K_ESCAPE:
       break_set = 1

if break_set:
   break

Cheers,

Ariel


On Mon, Aug 17, 2009 at 11:33 PM, Dav Clark<davclark@xxxxxxxxxxxx> wrote:
> Hey Rachel,
>
> If you're running the app in a window, I'm surprised it doesn't capture > focus when it starts... but it should certainly capture focus if it's full
> screen. Is that also a problem in full screen?
>
> When you are in full screen mode, you can use some operating system escape > thingie to exit. e.g. ctrl-alt-delete in windows, cmd-opt-escape in OSX, I > have no idea in linux & friends. Ultimately, both of these issues are > determined by the OS, and may be configurable in some cases - especially in > linux. For example, you can set in X11 whether a new application will take
> focus or not.
>
> But anyway, I think this is a general enough issue that it's worth posting > to the list, and I think you shouldn't hold back there... it's not a very
> high volume list!
>
> Cheers,
> Dav
>
> On Aug 17, 2009, at 6:57 PM, Rachel Denison wrote:
>
>> Hi Dav,
>>
>> I remember you mentioning that you are a vision egg devotee, and I was >> wondering if I could run a question by you before resorting to mailing the >> list. I have an experiment that runs on my full laptop screen, which I >> mirror onto the subject's display. The program takes key presses from the >> subject, but before it will recognize them, I have to click the screen, as >> though to give control of key presses to the visegg window. My forgetting to >> click the screen while scanning can cause confusion when the subject tries >> to press a button and nothing happens and can result in the scanner setting >> the program running at the wrong time, so I'd like to avoid this :) Is there >> any way of ensuring that keyboard control is immediately turned over to the
>> visegg program, without my having to click on the screen?
>>
>> Along these lines, I'd like to have some way of immediately exiting the >> program while it is running, in case something goes awry. When the visegg >> display is not taking up the full screen, it's easy enough to ctrl +c in the >> terminal and stop the program, but when it is a full screen display, the >> machine seems reluctant to let me switch control to the terminal and enter >> any commands. Do you know of an easy way to quit a visegg program while it >> is running on full screen? Or, do you have some other way of displaying your >> experiment in the scanner besides mirroring from your computer that still
>> gives precise timing?
>>
>> Any help would be much appreciated!
>>
>> Thanks,
>>
>> Rachel
>>
>>
>
> ======================================
> The Vision Egg mailing list
> Archives: //www.freelists.org/archives/visionegg
> Website: http://www.visionegg.org/mailinglist.html
>



--
Ariel Rokem
Helen Wills Neuroscience Institute
University of California, Berkeley
http://argentum.ucbso.berkeley.edu/ariel
The Vision Egg mailing list
Archives: //www.freelists.org/archives/visionegg
Website: http://www.visionegg.org/mailinglist.html



Other related posts: