I'm trying to show the Searchbar on my application using keyboard shortcuts.
While the keyboard shortcuts work perfectly using a Windows keyboard, the code fails when I'm using a Mac machine with a Mac keyboard.
Following is the function which I've written -
var osName = "Unknown OS";
if (navigator.appVersion.indexOf("Win") != -1) osName = "Windows";
if (navigator.appVersion.indexOf("Mac") != -1) osName = "MacOS";
function showSearchBarOnKeyPress() {
$(document).keydown(function (e) {
if ((e.ctrlKey && e.altKey && e.key === "z") || (osName === "MacOS" && e.keyCode === 90 && e.keyCode === 17 && e.keyCode === 91)) {
searchBarIsShown();
}
});
}
Initially I didn't have the '||' condition in the 'If' statement. The first condition works when using a Windows keyboard. When I checked on a Mac it didn't work. So I had to put in the '||' condition.
For the MacOS condition initially I had used keycodes - 59,55 and 6 as shown in this reference - https://eastmanreference.com/complete-list-of-applescript-key-codes
On checking in the Mac machine, the keycodes detected were - 90,91 and 17 which I then replaced.
But it still doesn't work.
Can someone please provide their insights/thoughts on this issue?
Thanks