@@ -32,7 +32,7 @@ Add `@violentmonkey/shortcut` to the [meta block](/api/metadata-block/) of our s
3232And access all exports under ` VM.shortcut ` :
3333
3434``` js
35- VM . shortcut . register ( ' c-i ' , () => { /* c-i pressed */ }) ;
35+ const { register } = VM . shortcut ;
3636```
3737
3838### Option 2. Installation
@@ -51,29 +51,27 @@ And use it in our code:
5151
5252``` js
5353import { register } from ' @violentmonkey/shortcut' ;
54-
55- register (' c-i' , () => {/* c-i pressed */ });
5654```
5755
58- ## Usage
56+ ## Quick Start
5957
60- Now we can easily register a keyboard shortcut:
58+ Easily register a keyboard shortcut:
6159
6260``` js
6361VM .shortcut .register (' c-i' , () => {
6462 console .log (' You just pressed Ctrl-I' );
6563});
6664```
6765
68- We can even register a key sequence:
66+ Register a key sequence:
6967
7068``` js
7169VM .shortcut .register (' c-a c-b' , () => {
7270 console .log (' You just pressed Ctrl-A Ctrl-B sequence' );
7371});
7472```
7573
76- We can disable and enable all key bindings at any time:
74+ Disable and enable all key bindings at any time:
7775
7876``` js
7977// Disable all key bindings temporarily
@@ -83,4 +81,23 @@ VM.shortcut.disable();
8381VM .shortcut .enable ();
8482```
8583
84+ ## Shortcut for Menu Command
85+
86+ Register a menu command with a shortcut:
87+
88+ ``` js
89+ const shortcut = ' c-g c-g' ;
90+ const name = ' Good Game' ;
91+ const handler = () => alert (' Good Game!' );
92+
93+ // Register menu command
94+ const menuName = ` ${ name} (${ VM .shortcut .reprShortcut (shortcut)} )` ;
95+ GM_registerMenuCommand (menuName, handler);
96+
97+ // Register shortcut
98+ VM .shortcut .register (shortcut, handler);
99+ ```
100+
101+ See [ @violentmonkey/shortcut ] [ vm-shortcut ] for more advanced usage.
102+
86103[ vm-shortcut ] : https://github.com/violentmonkey/vm-shortcut
0 commit comments