Key or Script to Close an HTML Popup?

Is there a way to close an HTML popup using keys on the keyboard, instead of moving the mouse to the “X” and closing the dialog?

I’ve mapped an XBOX controller for everything and it’s amazing; works very well. But the one last holdup is being able to close a dialog box.

If I can assign a key anywhere on the keyboard to close the dialog box, then I can close the HTML popup very easily. This would also be helpful in general for keyboard users in the space.

I’m very open to writing a javascript ‘listener’ or something like that to code it into the scene to look for an event like that. Just looking for guidance if anyone has done it already. Thanks!

Figured it out. So the trick is to add this globally:

// Ensure the viewer is initialized globally if needed
var viewer = WALK.getViewer();

// Add global event listener for keydown to close popups
document.addEventListener(‘keydown’, function (event) {
if (event.key.toLowerCase() === ‘c’) {
var hiddenCloseButtons = document.querySelectorAll(‘.hiddenCloseButton’);
hiddenCloseButtons.forEach(function(button) {; // Simulate the click event for all hidden close buttons

Then also append this to any message:

  '  <button id="hiddenCloseButtonController" class="hiddenCloseButton" style="display:none;" onclick="document.querySelector(\'.ext-popup-close-button\').click();">Hidden Close</button>' + // Hidden close button