Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/discord/globalKeybinds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ export function registerGlobalKeybinds() {
const keybinds = getConfig("keybinds");
keybinds.forEach((keybind: Keybind) => {
if (keybind.enabled && keybind.global) {
globalShortcut.register(keybind.accelerator, () => {
runAction(keybind);
});
try {
globalShortcut.register(keybind.accelerator, () => {
runAction(keybind);
});
} catch {}
}
});
}
Expand Down
14 changes: 10 additions & 4 deletions src/shelter/settings/components/KeybindMaker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const KeybindMaker = (props: { close: () => void }) => {

let logged: string[] = [];
let containsNonModifier = false;
let containsNumpadKey = false;
let timeout: NodeJS.Timeout | null = null;
function log(event: KeyboardEvent) {
const key = event.key.replace(" ", "Space");
Expand All @@ -41,7 +42,11 @@ export const KeybindMaker = (props: { close: () => void }) => {
} else {
console.log(key);
logged.unshift(key);
if (event.location === 0) containsNonModifier = true;
if (event.location === 0) {
containsNonModifier = true;
} else if (event.location === 3) {
containsNumpadKey = true;
}
setAccelerator(logged.join("+"));
}
if (timeout) clearTimeout(timeout);
Expand All @@ -66,6 +71,7 @@ export const KeybindMaker = (props: { close: () => void }) => {

logged = [];
containsNonModifier = false;
containsNumpadKey = false;
setAccelerator("");
console.log("Recording start");
document.body.addEventListener("keyup", log);
Expand Down Expand Up @@ -93,8 +99,8 @@ export const KeybindMaker = (props: { close: () => void }) => {
<ModalBody>
<span style="display: flex">
<Header tag={HeaderTags.H5}>Accelerator</Header>
<Show when={!recording() && accelerator() && !containsNonModifier}>
<p class={classes.error}>Modifier-only shortcuts are not supported.</p>
<Show when={containsNumpadKey || (!recording() && accelerator() && !containsNonModifier)}>
<p class={classes.error}>This key combination is invalid or not supported.</p>
</Show>
</span>
<div class={classes.grabBox}>
Expand Down Expand Up @@ -152,7 +158,7 @@ export const KeybindMaker = (props: { close: () => void }) => {
confirmText="Add"
onConfirm={save}
close={props.close}
disabled={recording() || !accelerator() || !containsNonModifier}
disabled={recording() || !accelerator() || !containsNonModifier || containsNumpadKey}
/>
</ModalRoot>
);
Expand Down
Loading