I was looking at the GM_registerMenuCommand function in Tampermonkey and I noticed a third parameter called accessKey
and thought it is to pass a hotkey to trigger this command.
What's the format of the parameter passed and am I wrong in assuming this is what it does?
I couldn't find documentation on the parameter anywhere. Does anyone here ever used it before?
The syntax for that function is:
GM_registerMenuCommand (menuName, callbackFunction, accessKey)
accessKey
, if supplied, must be a single letter of the string passed-in as menuName
.From Menu Design Guidelines(Number 8):
Dropdowns (both menus and boxes) should support not only mouse input, but keys as well. In dropdown menus, access keys should enable users to quickly select a visible option without using the mouse. In a dropdown box, users should be able to type a letter and quickly navigate to options starting with that letter.
(Emphasis added.)
Important: Access keys are different from, and in addition to, any command shortcuts ("hotkeys").
Here's a sample working Tampermonkey script that illustrates the use:
// ==UserScript==
// @name _GM_registerMenuCommand demo
// @match https://stackoverflow.com/questions/56024629/*
// @match *://YOUR_SERVER.COM/YOUR_PATH/*
// @grant GM_registerMenuCommand
// ==/UserScript==
/*-- GM_registerMenuCommand (menuName, callbackFunction, accessKey)
*/
GM_registerMenuCommand ("Say Hello", helloFunc, "H");
function helloFunc () {
console.log ("Say hello to my little script.");
}
If you install and run this via Tampermonkey you will see (click for larger image):
accessKey
parameter, for now.