Browse Source

finish arrow holding

finalv2
Backpack 2 months ago
parent
commit
cc6e5bb16f
2 changed files with 30 additions and 10 deletions
  1. +3
    -1
      src/hand_landmark/detector.ts
  2. +27
    -9
      src/hand_landmark/gesture_handler.ts

+ 3
- 1
src/hand_landmark/detector.ts View File

@ -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)) {

+ 27
- 9
src/hand_landmark/gesture_handler.ts View File

@ -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;
}
}

Loading…
Cancel
Save