[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] osx (mavericks) keyboard focus



Just to follow up -- it looks like this has something to do with the
selction of the default SDL videodriver. The fink version of pygame
apparently defaults to the mac native drivers, which doesn't appear to
accept keyboard or mouse input quite properly (as far as my app's
concerned at least). But, if I force SDL to use the x11 driver by
setting $SDL_VIDEODRIVER, it all works fine, just like under linux.

Interestingly, this seems to be reversed in the macports version of
pygame, where the default is to use the x11 driver, which is why the
keyboard stuff worked out of the box, I think.

Unfortunately, my app uses pygame AND tkinter, and the macports
version of tkinter apparently uses the native drivers and fink uses
x11. Go figure.. I don't have time to dive into the causes, but the
bottom line is that with fink if you set SDL_VIDEODRIVER=x11 before
initializing the pygame library everything works/looks just like under
linux...

/jamie


On Wed, Dec 10, 2014 at 4:48 PM, Mazer, James <james.mazer@xxxxxxxx> wrote:
> Thatâs sort of what I suspected â itâs something about the fink
> package.. unfortunately, Iâm using fink because there are other parts
> of the program that need fink (or rather, I had trouble with using the
> macport versions and the native versionâs a total disaster for this
> project).
> Thanks.
> /jamie
>
>
> On Wed, Dec 10, 2014 at 4:45 PM, J Dunford <smilechaser@xxxxxxxxxxxxxxx> wrote:
>> I tried this and it seems to work.
>>
>> - OS Mavericks (10.9.5)
>> - MacBook Pro Retina
>> - pygame 1.9.1 via macports
>> - ran from terminal using: python2.7 x.py (where x.py is the file name I copied your code sample into)
>>
>> For me the focus changed to the pygame window and when I pressed escape the program terminated (as expected).
>>
>> The only difference I can see between your setup and mine is that I installed PG through macports and you used fink. Could that make a difference?
>>
>> Maybe you could try installing pygame through the .dmg package and see if that makes a difference? Otherwise Iâm not sure what to suggestâ
>>
>> HTH,
>> Joe
>>
>>
>> On Dec 10, 2014, at 13:35, James Mazer <james.mazer@xxxxxxxx> wrote:
>>
>>> Is there a trick for getting pygame to take the keyboard focus under
>>> osx? I'm trying to port an app from linux and ran into something odd.
>>> This simple program:
>>>
>>> import pygame
>>> pygame.init()
>>> screen = pygame.display.set_mode((100,100))
>>> while 1:
>>>        pygame.event.pump()
>>>        if pygame.key.get_pressed()[pygame.K_ESCAPE]:
>>>                break
>>>
>>> doesn't work under osx (python 2.7 & pygame 1.9.1 via fink). The
>>> pygame window appears and changes color when clicked indicating it has
>>> the focus (and pygame.key.get_focused returns 1), but clicks in the
>>> pygame window are directed to the terminal where the program was run
>>> from (get_pressed() is always all zeros).
>>>
>>> Am I missing something obvious here? This works fine under linux. An
>>> hours or so of googling seems to indicate others have had this
>>> problem, but there's no obvious answer and nothing recent.
>>>
>>> thanks,
>>> /jamie
>>>
>>> --
>>> James Mazer
>>> Department of Neurobiology
>>> Yale School of Medicine
>>> phone: 203-737-5853
>>> fax: 203-785-5263
>>> url: http://jackknife.med.yale.edu
>>
>
>
>
> --
> James Mazer
> Department of Neurobiology
> Yale School of Medicine
> phone: 203-737-5853
> fax: 203-785-5263
> url: http://jackknife.med.yale.edu



-- 
James Mazer
Department of Neurobiology
Yale School of Medicine
phone: 203-737-5853
fax: 203-785-5263
url: http://jackknife.med.yale.edu