Skip to content

Commit 8b30fdf

Browse files
committed
Adds ability for user to use Meta key instead of alt for keybindings
- includes dynamically updating keybinding list
1 parent d924ede commit 8b30fdf

File tree

4 files changed

+99
-75
lines changed

4 files changed

+99
-75
lines changed

src/web/BindingsWaiter.js

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ const BindingsWaiter = function (app, manager) {
2323
* @param {event} e
2424
*/
2525
BindingsWaiter.prototype.parseInput = function(e) {
26-
if (e.ctrlKey && e.altKey) {
26+
let modKey = e.altKey;
27+
if (this.app.options.useMetaKey) modKey = e.metaKey;
28+
if (e.ctrlKey && modKey) {
2729
let elem;
2830
switch (e.code) {
2931
case "KeyF":
@@ -115,4 +117,88 @@ BindingsWaiter.prototype.parseInput = function(e) {
115117
}
116118
};
117119

120+
/**
121+
* Updates keybinding list when metaKey option is toggled
122+
*
123+
*/
124+
BindingsWaiter.prototype.updateKeybList = function() {
125+
let modWinLin = "Alt";
126+
let modMac = "Opt";
127+
if (this.app.options.useMetaKey) {
128+
modWinLin = "Win";
129+
modMac = "Cmd";
130+
}
131+
document.getElementById("keybList").innerHTML = `
132+
<tr>
133+
<td><b>Command</b></td>
134+
<td><b>Shortcut (Win/Linux)</b></td>
135+
<td><b>Shortcut (Mac)</b></td>
136+
</tr>
137+
<tr>
138+
<td>Place cursor in search field</td>
139+
<td>Ctrl+${modWinLin}+f</td>
140+
<td>Ctrl+${modMac}+f</td>
141+
<tr>
142+
<td>Place cursor in input box</td>
143+
<td>Ctrl+${modWinLin}+i</td>
144+
<td>Ctrl+${modMac}+i</td>
145+
</tr>
146+
<tr>
147+
<td>Place cursor in output box</td>
148+
<td>Ctrl+${modWinLin}+o</td>
149+
<td>Ctrl+${modMac}+o</td>
150+
</tr>
151+
<tr>
152+
<td>Place cursor in first argument field<br>of the next operation in the recipe</td>
153+
<td>Ctrl+${modWinLin}+.</td>
154+
<td>Ctrl+${modMac}+.</td>
155+
</tr>
156+
<tr>
157+
<td>Place cursor in first argument field<br>of the nth operation in the recipe</td>
158+
<td>Ctrl+${modWinLin}+[1-9]</td>
159+
<td>Ctrl+${modMac}+[1-9]</td>
160+
</tr>
161+
<tr>
162+
<td>Disable current operation</td>
163+
<td>Ctrl+${modWinLin}+d</td>
164+
<td>Ctrl+${modMac}+d</td>
165+
</tr>
166+
<tr>
167+
<td>Set/clear breakpoint</td>
168+
<td>Ctrl+${modWinLin}+b</td>
169+
<td>Ctrl+${modMac}+b</td>
170+
</tr>
171+
<tr>
172+
<td>Bake</td>
173+
<td>Ctrl+${modWinLin}+Space</td>
174+
<td>Ctrl+${modMac}+Space</td>
175+
</tr>
176+
<tr>
177+
<td>Step</td>
178+
<td>Ctrl+${modWinLin}+'</td>
179+
<td>Ctrl+${modMac}+'</td>
180+
</tr>
181+
<tr>
182+
<td>Clear recipe</td>
183+
<td>Ctrl+${modWinLin}+c</td>
184+
<td>Ctrl+${modMac}+c</td>
185+
</tr>
186+
<tr>
187+
<td>Save to file</td>
188+
<td>Ctrl+${modWinLin}+s</td>
189+
<td>Ctrl+${modMac}+s</td>
190+
</tr>
191+
<tr>
192+
<td>Load recipe</td>
193+
<td>Ctrl+${modWinLin}+l</td>
194+
<td>Ctrl+${modMac}+l</td>
195+
</tr>
196+
<tr>
197+
<td>Move output to input</td>
198+
<td>Ctrl+${modWinLin}+m</td>
199+
<td>Ctrl+${modMac}+m</td>
200+
</tr>
201+
`;
202+
};
203+
118204
export default BindingsWaiter;

src/web/Manager.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Manager.prototype.setup = function() {
7878
this.recipe.initialiseOperationDragNDrop();
7979
this.controls.autoBakeChange();
8080
this.seasonal.load();
81+
this.bindings.updateKeybList();
8182
};
8283

8384

@@ -91,7 +92,6 @@ Manager.prototype.initialiseEventListeners = function() {
9192
window.addEventListener("focus", this.window.windowFocus.bind(this.window));
9293
window.addEventListener("statechange", this.app.stateChange.bind(this.app));
9394
window.addEventListener("popstate", this.app.popState.bind(this.app));
94-
window.addEventListener("keydown", this.bindings.parseInput.bind(this.bindings));
9595
// Controls
9696
document.getElementById("bake").addEventListener("click", this.controls.bakeClick.bind(this.controls));
9797
document.getElementById("auto-bake").addEventListener("change", this.controls.autoBakeChange.bind(this.controls));
@@ -166,6 +166,10 @@ Manager.prototype.initialiseEventListeners = function() {
166166
this.addDynamicListener(".option-item select", "change", this.options.selectChange, this.options);
167167
document.getElementById("theme").addEventListener("change", this.options.themeChange.bind(this.options));
168168

169+
//Keybindings
170+
window.addEventListener("keydown", this.bindings.parseInput.bind(this.bindings));
171+
$(document).on("switchChange.bootstrapSwitch", ".option-item input:checkbox#useMetaKey", this.bindings.updateKeybList.bind(this.bindings));
172+
169173
// Misc
170174
document.getElementById("alert-close").addEventListener("click", this.app.alertCloseClick.bind(this.app));
171175
};

src/web/html/index.html

Lines changed: 6 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,10 @@ <h4 class="modal-title">Options</h4>
325325
<input type="checkbox" option="showErrors" id="showErrors" checked />
326326
<label for="showErrors"> Operation error reporting (recommended) </label>
327327
</div>
328+
<div class="option-item">
329+
<input type="checkbox" option="useMetaKey" id="useMetaKey" />
330+
<label for="errorTimeout"> Use meta (Windows/Command ⌘) key for keybindings </label>
331+
</div>
328332
<div class="option-item">
329333
<input type="number" option="errorTimeout" id="errorTimeout" />
330334
<label for="errorTimeout"> Operation error timeout in ms (0 for never) </label>
@@ -402,8 +406,7 @@ <h4 class="modal-title">CyberChef - The Cyber Swiss Army Knife</h4>
402406
About
403407
</a></li>
404408
<li role="presentation"><a href="#keybindings" aria-controls="messages" role="tab" data-toggle="tab">
405-
<!-- Icon is a placeholder -->
406-
<img aria-hidden="true" src="<%- require('../static/images/code-16x16.png') %>" alt="Code Icon"/>
409+
<img aria-hidden="true" src="<%- require('../static/images/code-16x16.png') %>" alt="List Icon"/>
407410
Keybindings
408411
</a></li>
409412
</ul>
@@ -482,77 +485,7 @@ <h5><strong>Aim</strong></h5>
482485
<p>It’s the Cyber Swiss Army Knife.</p>
483486
</div>
484487
<div role="tabpanel" class="tab-pane" id="keybindings" style="padding: 20px;">
485-
<table class="table table-condensed table-bordered">
486-
<tr>
487-
<td><b>Command</b></td>
488-
<td><b>Shortcut (Win/Linux)</b></td>
489-
<td><b>Shortcut (Mac)</b></td>
490-
</tr>
491-
<tr>
492-
<td>Place cursor in search field</td>
493-
<td>Ctrl+Alt+f</td>
494-
<td>Ctrl+Opt+f</td>
495-
<tr>
496-
<td>Place cursor in input box</td>
497-
<td>Ctrl+Alt+i</td>
498-
<td>Ctrl+Opt+i</td>
499-
</tr>
500-
<tr>
501-
<td>Place cursor in output box</td>
502-
<td>Ctrl+Alt+o</td>
503-
<td>Ctrl+Opt+o</td>
504-
</tr>
505-
<tr>
506-
<td>Place cursor in first argument field<br>of the next operation in the recipe</td>
507-
<td>Ctrl+Alt+.</td>
508-
<td>Ctrl+Opt+.</td>
509-
</tr>
510-
<tr>
511-
<td>Place cursor in first argument field<br>of the nth operation in the recipe</td>
512-
<td>Ctrl+Alt+[1-9]</td>
513-
<td>Ctrl+Opt+[1-9]</td>
514-
</tr>
515-
<tr>
516-
<td>Disable current operation</td>
517-
<td>Ctrl+Alt+d</td>
518-
<td>Ctrl+Opt+d</td>
519-
</tr>
520-
<tr>
521-
<td>Set/clear breakpoint</td>
522-
<td>Ctrl+Alt+b</td>
523-
<td>Ctrl+Opt+b</td>
524-
</tr>
525-
<tr>
526-
<td>Bake</td>
527-
<td>Ctrl+Alt+Space</td>
528-
<td>Ctrl+Opt+Space</td>
529-
</tr>
530-
<tr>
531-
<td>Step</td>
532-
<td>Ctrl+Alt+'</td>
533-
<td>Ctrl+Opt+'</td>
534-
</tr>
535-
<tr>
536-
<td>Clear recipe</td>
537-
<td>Ctrl+Alt+c</td>
538-
<td>Ctrl+Opt+c</td>
539-
</tr>
540-
<tr>
541-
<td>Save to file</td>
542-
<td>Ctrl+Alt+s</td>
543-
<td>Ctrl+Opt+s</td>
544-
</tr>
545-
<tr>
546-
<td>Load recipe</td>
547-
<td>Ctrl+Alt+l</td>
548-
<td>Ctrl+Opt+l</td>
549-
</tr>
550-
<tr>
551-
<td>Move output to input</td>
552-
<td>Ctrl+Alt+m</td>
553-
<td>Ctrl+Opt+m</td>
554-
</tr>
555-
</table>
488+
<table class="table table-condensed table-bordered" id="keybList"></table>
556489
</div>
557490
</div>
558491
</div>

src/web/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ function main() {
4646
errorTimeout: 4000,
4747
attemptHighlight: true,
4848
theme: "classic",
49+
useMetaKey: false
4950
};
5051

5152
document.removeEventListener("DOMContentLoaded", main, false);

0 commit comments

Comments
 (0)