If you want to only listen for a specific element's click event instead of the entire window, you can add a click listener directly to that element.
Here is an example:
index.html
<button id="button">button</button>
script.js
const buttonEl = document.getElementById("#button")
buttonEl.addEventListener("click", function() {
// handle click
})
Edit: While I have not tested this myself, I believe you may be able to achieve a similar outcome by using the blur event.
Here is an example:
document.addEventListener('blur', function(){console.log('document blur')});
window.addEventListener('blur', function(){console.log('window blur')});