Selected application loses focus
The issue was due to a dockbar application grabbing the focus occasionally. One such culprit: older versions of Google Drive, as seen here: https://productforums.google.com/forum/#!msg/drive/epLdP4Bny5w/gKQsxwDMoUAJ

However, any application can grab and keep focus. 

Note: for me the problem was a very outdated version of Google Drive.