Ctrl + left click, right click and wheel-click

In general, is there a way set actions to the different types of mouse-clicks?

More specifically, how can i open a view in a new tab when a row in a table is clicked in a specific fashion? Normal left click should open in current window, other clicks should open in new tab.

Tried the following, but it does not work (chatgpt code…):

document.addEventListener('keydown', function (event) {
  if (event.ctrlKey || event.metaKey) {
      // Handle macOS Command key or Windows meta key
      return true;
  }
});

Hi!

To add more granular event handlers on different types of clicks and key combinations, you need to do this by using Run Code.

I added and tested the following code (generated by Gemini) inside an action with Run code (triggering a code snippet on CTRL/CMD + Click). The action can be triggered on app load or view load, and it works!

document.addEventListener('click', function(event) {
    // Check for Ctrl key on Windows/Linux or Meta key (Command key) on Mac
    if (event.ctrlKey || event.metaKey) {
        // Prevent the default behavior of the click if necessary
        // For example, if you don't want it to open a new tab when Ctrl/Cmd is pressed with a link
        // event.preventDefault();

        console.log("CTRL/CMD + Click detected!");

        // Your custom logic here
        // For example, if you want to perform a specific action based on the clicked element:
        // if (event.target.tagName === 'A') {
        //     console.log("Clicked on a link with CTRL/CMD:", event.target.href);
        // } else if (event.target.classList.contains('my-special-div')) {
        //     console.log("Clicked on a special div with CTRL/CMD");
        // }
    }
});
resolve()