Building on the answer by @Martin J.H. above, the below userscript was created, because Outlook Web was hijacking the Alt+arrow (and later just the Alt) keys on MacOS.
It should provide a headstart template for creating your own userscript.
Just uncomment the alert block in the handler function (possibly changing it to console.log, to make it less annoying) to check for the eventCodes that you need and add them to the array at the beginning of the file.
You will of course need a userscript manager like Greasemonkey, Tampermonkey (below is tested with this) or Violentmonkey. Greasyfork has a list of browsers and available plugins.
// ==UserScript==
// @name Fix Outlook Mac Hotkeys Hijacking
// @description Disables Outlook from highjacking Mac keyboard shortcuts
// @copyright 2024, phonique (https://github.com/phonique/userscript-stop-outlook-hijack/)
// @homepageURL https://github.com/phonique/userscript-stop-outlook-hijack
// @version 0.1.0
// @run-at document-start
// @match https://outlook.office.com/*
// @grant none
// @license MPL-2.0
// ==/UserScript==
// event codes for arrow keys (add your own here).
var eventCodes = ["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"];
// Possible keyboard events: keypress, keyup, keydown
// currently Outlook seems to only require keydown and keyup.
// Only keypress is not enough to disable Alt-key hijacking.
// We enable useCapture here, because we want to capture the event while
// it's trickling down the DOM and then ignore other Listeners that hijack
// our default Alt functionality with the cancelBubble() and
// stopImmediatePropagation() calls.
// see here: https://stackoverflow.com/questions/5657292/why-is-false-used-after-this-simple-addeventlistener-function/25591239#25591239
window.addEventListener('keydown', handler, true); // useCapture true, i.e. we are capturing the event while it's trickling down
window.addEventListener('keyup', handler, true); // useCapture true
// we don't need this for Outlook, but you might for your usecase
// window.addEventListener('keypress', handler, true);
function handler (e) {
// alert("eventCode: " + e.code + " eventKey: " + e.key); // debug here
// If you want to completely disable Alt hijacking, not just in textboxes
// uncomment the next and also comment out (or remove) the line following it.
// if (e.code === "AltRight" || e.code === "AltLeft" || e.key === "Alt") {
if ((e.code === "AltRight" || e.code === "AltLeft" || e.key === "Alt") && typeof(document.activeElement.role) !== 'undefined' && document.activeElement.role == 'textbox') {
e.cancelBubble = true;
e.stopImmediatePropagation();
}
// including previous UX-fixes
if (eventCodes.indexOf(e.code) != -1 && e.shiftKey && e.altKey) {
e.cancelBubble = true;
e.stopImmediatePropagation();
}
if (eventCodes.indexOf(e.code) != -1 && e.altKey) {
e.cancelBubble = true;
e.stopImmediatePropagation();
}
if (eventCodes.indexOf(e.code) != -1 && e.shiftKey && e.metaKey) {
e.cancelBubble = true;
e.stopImmediatePropagation();
}
if (eventCodes.indexOf(e.code) != -1 && e.shiftKey && e.ctrlKey) {
e.cancelBubble = true;
e.stopImmediatePropagation();
}
}