Поэтому я создаю мобильное приложение, используя выставку, которая отправляет позицию касания на сервер, чтобы я мог контролировать перемещение мыши. попробовал CHATGPT, но все еще столкнулся с проблемой.
Код: Выделить всё
const singlePan = Gesture.Pan()
.onBegin((e) => {
lastTranslationX = 0;
lastTranslationY = 0;
cursorVisible.value = 1;
cursorX.value = e.absoluteX;
cursorY.value = e.absoluteY;
})
.onUpdate((e) => {
// Calculate delta
const dx = e.translationX - lastTranslationX;
const dy = e.translationY - lastTranslationY;
cursorX.value = e.x;
cursorY.value = e.y;
const now = Date.now();
if (now - lastSentTime > 16) { // ~60fps throttle
if (onMove) runOnJS(onMove)(dx, dy);
}
lastTranslationX = e.translationX;
lastTranslationY = e.translationY;
})
.onEnd((e) => {
// Stop velocity and cursor movement immediately (no inertia)
velocityX.value = 0;
velocityY.value = 0;
cursorVisible.value = withSpring(0, { damping: 20 });
/* velocityX.value = e.velocityX;
velocityY.value = e.velocityY;
cursorX.value = withDecay({ velocity: velocityX.value, deceleration: 1 - (1 - friction) });
cursorY.value = withDecay({ velocity: velocityY.value, deceleration: 1 - (1 - friction) });
cursorVisible.value = withSpring(0, { damping: 20 });*/
})
.maxPointers(1);
< /code>
# c# code < /p>
private void MoveMouseBy(int dx, int dy)
{
INPUT[] inputs = new INPUT[1];
inputs[0].type = INPUT_MOUSE;
inputs[0].mi.dx = dx;
inputs[0].mi.dy = dy;
inputs[0].mi.mouseData = 0;
inputs[0].mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_MOVE_NOCOALESCE;
inputs[0].mi.time = 0;
inputs[0].mi.dwExtraInfo = IntPtr.Zero;
uint result = SendInput(1, inputs, Marshal.SizeOf(typeof(INPUT)));
if (result == 0)
{
Console.WriteLine("SendInput failed with error: " + Marshal.GetLastWin32Error());
}
}
public bool MoveMouseRelative(double dx, double dy, MousePadSize padSize)
{
double mobileWidth = padSize?.Width ?? 300; // fallback if missing
double mobileHeight = padSize?.Height ?? 500;
int screenWidth = Screen.PrimaryScreen.Bounds.Width;
int screenHeight = Screen.PrimaryScreen.Bounds.Height;
// Scale deltas: map mobile movement fractionally to PC pixels
double scaleX = (double)screenWidth / mobileWidth;
double scaleY = (double)screenHeight / mobileHeight;
double scaledDx = dx * scaleX;
double scaledDy = dy * scaleY;
accumX += scaledDx * sensitivity;
accumY += scaledDy * sensitivity; //
Подробнее здесь: [url]https://stackoverflow.com/questions/79733549/mousepad-app-issue-calculating-the-right-postions-diff-between-mobile-app-and-p[/url]
Мобильная версия