App not Frontmost

Moderator
Posts: 613
Joined: 2004.09
Post: #1
So here is my issue, Im using GetKeys for the first time. This works great and everything no sign of the missing GetKeys bug yet. Anyways everything works fine in Windowed and Full Screen till the user switches to another app. The game continues to accept inputs from any other app which is understandable normal behavior for get keys.

My question is, is there a way i can check to see if the game app is the front most app? This would allow me to either pause or ignore key inputs if it is not. I know there is something in com.apple.HIToolbox.menuBarShownNotification I just cant seem to be able to get it working correctly.

By the way i would REALLY like to avoid polling =D.

Thanks for the help in Advance guys.

Kyle Richter
DragonForged.com
Twitter: @kylerichter
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #2
You can register for Carbon events that notify you when your application is activated/deactivated. Take a look a kEventClassApplication/kEventAppActivated and kEventClassApplication/kEventAppDeactivated. When you receive a deactivate event, it's a good idea to pause your event loop timer and stop accepting input until you receive an activate event.

- Alex Diener
Quote this message in a reply
Moderator
Posts: 3,570
Joined: 2003.06
Post: #3
Don't use GetKeys. It's old and it doesn't work and it's not the right way to do things anymore. You should definitely be receiving keyboard events through a registered event handler instead.
Quote this message in a reply
Member
Posts: 277
Joined: 2004.10
Post: #4
You can easly build a event handler that basicly is the same as GetKeys....

You just "log" a key when you get a key down event and "un-log" a key when you get a key up.
(no GetKeys... no 72% of your time in GetKeys... LOL)

Global warming is caused by hobos and mooses
Quote this message in a reply
Moderator
Posts: 613
Joined: 2004.09
Post: #5
72% of the time =p. I have heard more like 1 out of 900 times.

Kyle Richter
DragonForged.com
Twitter: @kylerichter
Quote this message in a reply
Post Reply