@@ -32,7 +32,7 @@ Add `@violentmonkey/shortcut` to the [meta block](/api/metadata-block/) of our s
32
32
And access all exports under ` VM.shortcut ` :
33
33
34
34
``` js
35
- VM . shortcut . register ( ' c-i ' , () => { /* c-i pressed */ }) ;
35
+ const { register } = VM . shortcut ;
36
36
```
37
37
38
38
### Option 2. Installation
@@ -51,29 +51,27 @@ And use it in our code:
51
51
52
52
``` js
53
53
import { register } from ' @violentmonkey/shortcut' ;
54
-
55
- register (' c-i' , () => {/* c-i pressed */ });
56
54
```
57
55
58
- ## Usage
56
+ ## Quick Start
59
57
60
- Now we can easily register a keyboard shortcut:
58
+ Easily register a keyboard shortcut:
61
59
62
60
``` js
63
61
VM .shortcut .register (' c-i' , () => {
64
62
console .log (' You just pressed Ctrl-I' );
65
63
});
66
64
```
67
65
68
- We can even register a key sequence:
66
+ Register a key sequence:
69
67
70
68
``` js
71
69
VM .shortcut .register (' c-a c-b' , () => {
72
70
console .log (' You just pressed Ctrl-A Ctrl-B sequence' );
73
71
});
74
72
```
75
73
76
- We can disable and enable all key bindings at any time:
74
+ Disable and enable all key bindings at any time:
77
75
78
76
``` js
79
77
// Disable all key bindings temporarily
@@ -83,4 +81,23 @@ VM.shortcut.disable();
83
81
VM .shortcut .enable ();
84
82
```
85
83
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
+
86
103
[ vm-shortcut ] : https://github.com/violentmonkey/vm-shortcut
0 commit comments