feat(hotkey): add swipe shortcut

This commit is contained in:
AkiChase 2024-05-29 11:53:30 +08:00
parent 3547e9e17a
commit 996bc2517b
2 changed files with 51 additions and 0 deletions

View File

@ -17,6 +17,7 @@ import {
KeyObservation,
KeySight,
KeySteeringWheel,
KeySwipe,
KeyTap,
KeyTriggerWhenDoublePressedSkill,
KeyTriggerWhenPressedSkill,
@ -948,6 +949,37 @@ function addSightShortcuts(
});
}
function addSwipeShortcuts(
key: string,
relativeSize: { w: number; h: number },
// pos relative to the mask
pos: { x: number; y: number }[],
pointerId: number,
intervalBetweenPos: number
) {
for (const posObj of pos) {
posObj.x = Math.round((posObj.x / relativeSize.w) * store.screenSizeW);
posObj.y = Math.round((posObj.y / relativeSize.h) * store.screenSizeH);
}
addShortcut(
key,
async () => {
await swipe({
action: SwipeAction.Default,
pointerId,
screen: {
w: store.screenSizeW,
h: store.screenSizeH,
},
pos,
intervalBetweenPos,
});
},
undefined,
undefined
);
}
function createMouseRangeBox(): HTMLElement {
const box = document.createElement("div");
box.id = "mouseRangeBox";
@ -1387,6 +1419,16 @@ function applyKeyMappingConfigShortcuts(
item.pointerId
);
break;
case "Swipe":
asType<KeySwipe>(item);
addSwipeShortcuts(
item.key,
relativeSize,
item.pos,
item.pointerId,
item.intervalBetweenPos
);
break;
case "TriggerWhenPressedSkill":
asType<KeyTriggerWhenPressedSkill>(item);
addTriggerWhenPressedSkillShortcuts(

View File

@ -65,6 +65,14 @@ export interface KeyTap extends KeyBase {
time: number;
}
export interface KeySwipe extends KeyBase {
type: "Swipe";
pointerId: number;
key: string;
pos: { x: number; y: number }[];
intervalBetweenPos: number;
}
export type KeyMacroList = Array<{
type: "touch" | "sleep" | "swipe" | "key-input-mode";
args: any[];
@ -106,6 +114,7 @@ export type KeyMapping =
| KeyMacro
| KeyCancelSkill
| KeyTap
| KeySwipe
| KeySight
| KeyFire;