Detecting focus/blur to Corona window

Basically, I’ve got a input handling that detects the Ctrl down/up events. Now I’m using a screen capture application to record my sessions and the command to stop recording is Ctrl+F10. When I stop recording, the application automatically comes to the foreground and takes focus from Corona.

When I switch back to my Corona session, the game behaves as though Ctrl is still pressed because it never received the key up event, which was received by the video recording software instead when it stole focus.

What I would like to do instead is detect when the entire window has lost focus, for example the user switching apps, and manually set these keys as released. Is this possible?

I did read that I can detect application events here (https://docs.coronalabs.com/api/event/system/type.html) and resume/suspend will be useful for mobile devices that support keyboards, as I imagine that they would fire an event if the user switches apps, but I need this for Windows/Mac support.

Thanks for reading!

Right.  We currently do not have an API or event that’ll notify you when the window has gained or lost the focus.  It’s definitely something to consider in the future.

On Windows, you’ll only receive “key” events from the keyboard when your app window has the focus.  However, your app will still receive mouse and game controller events when your app window does not have the focus.  So, if your app supports that kind of control scheme, then that may help you out during the video recording process.

Thanks for the reply! I’ll file a feature request for this.

Undoubtedly this is a scenario most users will not experience, I do have personal experience playing games or using applications where another app rudely decides to take focus, and when I return to the application the scenario I described above happens.

Thanks again!

>> I do have personal experience playing games or using applications where another app rudely decides to take focus

Java update notifications are the worst offender.  It’s super rude by displaying a top-most-window that yanks me out of whatever I’m doing on the desktop.  And it does this to me everyday until I’m actually ready to do an update.  So, yeah, I agree with you that we’ll need to provide a solution of some kind.  We’ll get there.

Hi, I just want to bring this up again to the top. I’ve been experiencing this in some way or another recently, and I’d really like to be able to pause the game when the window loses focus.

Here is the associated feature request I filed: http://feedback.coronalabs.com/forums/188732-corona-sdk-feature-requests-feedback/suggestions/10612233-ability-to-detect-when-the-window-focuses-and-blur

Something like this makes perfect sense:
 

Runtime:addEventListener("system", function (event) local eventType = event.type; if eventType == "applicationBlur" then -- Execute when the user moves away from the app (e.g. Alt+Tab) elseif eventType == "applicationFocus" then -- Execute when the user moves back to the app end end);

Right.  We currently do not have an API or event that’ll notify you when the window has gained or lost the focus.  It’s definitely something to consider in the future.

On Windows, you’ll only receive “key” events from the keyboard when your app window has the focus.  However, your app will still receive mouse and game controller events when your app window does not have the focus.  So, if your app supports that kind of control scheme, then that may help you out during the video recording process.

Thanks for the reply! I’ll file a feature request for this.

Undoubtedly this is a scenario most users will not experience, I do have personal experience playing games or using applications where another app rudely decides to take focus, and when I return to the application the scenario I described above happens.

Thanks again!

>> I do have personal experience playing games or using applications where another app rudely decides to take focus

Java update notifications are the worst offender.  It’s super rude by displaying a top-most-window that yanks me out of whatever I’m doing on the desktop.  And it does this to me everyday until I’m actually ready to do an update.  So, yeah, I agree with you that we’ll need to provide a solution of some kind.  We’ll get there.

Hi, I just want to bring this up again to the top. I’ve been experiencing this in some way or another recently, and I’d really like to be able to pause the game when the window loses focus.

Here is the associated feature request I filed: http://feedback.coronalabs.com/forums/188732-corona-sdk-feature-requests-feedback/suggestions/10612233-ability-to-detect-when-the-window-focuses-and-blur

Something like this makes perfect sense:
 

Runtime:addEventListener("system", function (event) local eventType = event.type; if eventType == "applicationBlur" then -- Execute when the user moves away from the app (e.g. Alt+Tab) elseif eventType == "applicationFocus" then -- Execute when the user moves back to the app end end);