diff --git a/src/hand_landmark/detector.ts b/src/hand_landmark/detector.ts index e06a136..acb27e7 100644 --- a/src/hand_landmark/detector.ts +++ b/src/hand_landmark/detector.ts @@ -35,6 +35,7 @@ export enum HandGesture { // 游戏手势 DIRECTION_RIGHT = "direction_right", JUMP = "jump", // 食指 + 拇指上抬 + RIGHTJUMP = "rightjump", } interface HandLandmark { @@ -232,7 +233,8 @@ export class Detector { // 其他手势 ["0,0,0,0,0", HandGesture.VOICE_GESTURE_STOP], - ["1,1,1,0,0", HandGesture.JUMP], + ["0,1,1,0,0", HandGesture.JUMP], + ["1,1,1,0,0", HandGesture.RIGHTJUMP], ]); if (gestureMap.has(fingerState)) { diff --git a/src/hand_landmark/gesture_handler.ts b/src/hand_landmark/gesture_handler.ts index bc9cc0a..03dea7d 100644 --- a/src/hand_landmark/gesture_handler.ts +++ b/src/hand_landmark/gesture_handler.ts @@ -157,12 +157,6 @@ export class GestureHandler { private lastDeleteTime: number = 0; - // 小游戏 - private lastArrowLeftTime = 0; - private lastArrowRightTime = 0; - private lastJumpTime = 0; - private readonly DIRECTION_INTERVAL = 500; // 防抖间隔(毫秒) - constructor() { this.triggerAction = new TriggerAction(); this.app_store = use_app_store(); @@ -322,6 +316,13 @@ export class GestureHandler { } } + private holdKey(key: string, repeat: number = 5, delay: number = 50) { + for (let i = 0; i < repeat; i++) { + setTimeout(() => { + this.triggerAction.sendKeys(key); + }, i * delay); + } + } /** * 处理删除手势 @@ -332,7 +333,7 @@ export class GestureHandler { return; } this.lastDeleteTime = now; - this.triggerAction.sendKeys("left"); + this.holdKey("left", 50); // 模拟左键长按 } @@ -342,7 +343,7 @@ export class GestureHandler { return; } this.lastDeleteTime = now; - this.triggerAction.sendKeys("right"); + this.holdKey("right", 50); } @@ -352,9 +353,22 @@ export class GestureHandler { return; } this.lastDeleteTime = now; - this.triggerAction.sendKeys("up"); + this.holdKey("up", 20); // 模拟上键长按 } + private handleRightJump() { + const now = Date.now(); + if (now - this.lastDeleteTime < 300) { + return; + } + this.lastDeleteTime = now; + // 先按右,再按上,模拟组合跳跃(可根据游戏实际逻辑调整) + this.holdKey("right", 50); + setTimeout(() => { + this.holdKey("up", 20); + }, 100); // 延迟一点时间再跳 + } + /** * 处理停止手势 */ @@ -446,6 +460,10 @@ export class GestureHandler { case HandGesture.JUMP: this.handleJump(); break; + + case HandGesture.RIGHTJUMP: + this.handleRightJump(); + break; } }