diff --git a/src/hotkey.ts b/src/hotkey.ts index 8fe93bf..511f41d 100644 --- a/src/hotkey.ts +++ b/src/hotkey.ts @@ -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(item); + addSwipeShortcuts( + item.key, + relativeSize, + item.pos, + item.pointerId, + item.intervalBetweenPos + ); + break; case "TriggerWhenPressedSkill": asType(item); addTriggerWhenPressedSkillShortcuts( diff --git a/src/keyMappingConfig.ts b/src/keyMappingConfig.ts index 55e9dd1..6dec92a 100644 --- a/src/keyMappingConfig.ts +++ b/src/keyMappingConfig.ts @@ -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;