• Post Reply Bookmark Topic Watch Topic
  • New Topic

Detect Loss of Focus For Entire App  RSS feed

 
Josh Britton
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am looking for a way to detect when none of my app's windows are active. I need to count how many times my user 'leaves' my app. For example, I would like to detect when a user on a pc uses alt-tab to switch to different app. I played with adding a PropertyChangeListener to the KeyboardFocusManager and then checking for a null activeWindow property. Unfortunately, this gave me false positives, because the activeWindow is temporarily set to null even when switching between windows in my app. Any ideas?

Thanks.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
alt-tab would generally be processed/consumed by the os before it gets to your app

you could try adding a windowListener and in windowDeactivated() iterate getFrames()
checking isActive(), but I'm not sure getFrames() is entirely reliable - would need major testing
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!