mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-01-31 23:29:27 +08:00
feat: 预览要设置成的快捷键
This commit is contained in:
parent
d10022c9e8
commit
9b77660818
@ -136,7 +136,10 @@ function unwarpAssist(assist: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getKeyShow(key: KeyCode, assist: number) {
|
function getKeyShow(key: KeyCode, assist: number) {
|
||||||
return unwarpAssist(assist) + KeyCodeUtils.toString(key);
|
return (
|
||||||
|
unwarpAssist(assist) +
|
||||||
|
(key === KeyCode.Unknown ? '' : KeyCodeUtils.toString(key))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function select(id: string, index: number) {
|
function select(id: string, index: number) {
|
||||||
@ -146,43 +149,72 @@ function select(id: string, index: number) {
|
|||||||
|
|
||||||
function keyup(e: KeyboardEvent) {
|
function keyup(e: KeyboardEvent) {
|
||||||
if (selectedKey.id === 'none') return;
|
if (selectedKey.id === 'none') return;
|
||||||
|
e.preventDefault();
|
||||||
const code = keycode(e.keyCode);
|
const code = keycode(e.keyCode);
|
||||||
if (
|
|
||||||
code === KeyCode.Ctrl ||
|
|
||||||
code === KeyCode.Shift ||
|
|
||||||
code === KeyCode.Alt
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const assist = generateBinary([e.ctrlKey, e.shiftKey, e.altKey]);
|
const assist = generateBinary([e.ctrlKey, e.shiftKey, e.altKey]);
|
||||||
const id =
|
const id =
|
||||||
selectedKey.index === -1
|
selectedKey.index === -1
|
||||||
? selectedKey.id
|
? selectedKey.id
|
||||||
: `${selectedKey.id}_${selectedKey.index}`;
|
: `${selectedKey.id}_${selectedKey.index}`;
|
||||||
|
|
||||||
hotkey.set(id, code, assist);
|
|
||||||
const key = keyData[selectedGroup.value][selectedKey.id].keys.find(
|
const key = keyData[selectedGroup.value][selectedKey.id].keys.find(
|
||||||
v => v.index === selectedKey.index
|
v => v.index === selectedKey.index
|
||||||
);
|
);
|
||||||
|
|
||||||
if (key) {
|
if (key) {
|
||||||
key.key = code;
|
if (
|
||||||
key.assist = assist;
|
code === KeyCode.Ctrl ||
|
||||||
|
code === KeyCode.Shift ||
|
||||||
|
code === KeyCode.Alt
|
||||||
|
) {
|
||||||
|
const data = hotkey.data[id];
|
||||||
|
key.assist = generateBinary([data.ctrl, data.shift, data.alt]);
|
||||||
|
key.key = data.key;
|
||||||
|
} else {
|
||||||
|
key.key = code;
|
||||||
|
key.assist = assist;
|
||||||
|
hotkey.set(id, code, assist);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
selectedKey.id = 'none';
|
selectedKey.id = 'none';
|
||||||
selectedKey.index = -1;
|
selectedKey.index = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function keydown(e: KeyboardEvent) {
|
||||||
|
if (selectedKey.id === 'none') return;
|
||||||
|
e.preventDefault();
|
||||||
|
const code = keycode(e.keyCode);
|
||||||
|
const assist = generateBinary([e.ctrlKey, e.shiftKey, e.altKey]);
|
||||||
|
const key = keyData[selectedGroup.value][selectedKey.id].keys.find(
|
||||||
|
v => v.index === selectedKey.index
|
||||||
|
);
|
||||||
|
if (!key) return;
|
||||||
|
key.assist = assist;
|
||||||
|
key.key = KeyCode.Unknown;
|
||||||
|
|
||||||
|
if (
|
||||||
|
code !== KeyCode.Ctrl &&
|
||||||
|
code !== KeyCode.Shift &&
|
||||||
|
code !== KeyCode.Alt
|
||||||
|
) {
|
||||||
|
key.key = code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ban other keys
|
// ban other keys
|
||||||
gameKey.disable();
|
gameKey.disable();
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
document.addEventListener('keyup', keyup);
|
document.addEventListener('keyup', keyup);
|
||||||
|
document.addEventListener('keydown', keydown);
|
||||||
});
|
});
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
gameKey.enable();
|
gameKey.enable();
|
||||||
document.removeEventListener('keyup', keyup);
|
document.removeEventListener('keyup', keyup);
|
||||||
|
document.removeEventListener('keydown', keydown);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user