Untitled
unknown
plain_text
a year ago
3.3 kB
14
Indexable
// Metoda do symulacji zdarzenia myszki
public static void SimulateMouseEvent(
int x,
int y,
string eventType,
bool isLeftButton,
bool isPressed,
int clientScreenWidth,
int clientScreenHeight)
{
InputSimulator inputSimulator = new InputSimulator();
// Pobranie rozdzielczości ekranu lokalnego
var (localWidth, localHeight) = GetPhysicalScreenResolution();
// Debugowanie - rozdzielczość ekranu klienta i lokalnego
Debug.WriteLine($"Client screen resolution: ({clientScreenWidth}, {clientScreenHeight})");
Debug.WriteLine($"Local screen resolution: ({localWidth}, {localHeight})");
// Normalizacja współrzędnych w oparciu o ekran klienta
float normalizedX = x / (float)clientScreenWidth;
float normalizedY = y / (float)clientScreenHeight;
// Debugowanie - Normalizacja współrzędnych
Debug.WriteLine($"Normalized coords: ({normalizedX}, {normalizedY})");
// Sprawdzenie proporcji ekranu klienta i lokalnego
float aspectRatioClient = clientScreenWidth / (float)clientScreenHeight;
float aspectRatioLocal = localWidth / (float)localHeight;
Debug.WriteLine($"Aspect ratios: Client = {aspectRatioClient}, Local = {aspectRatioLocal}");
// Korekta proporcji, jeśli są różne
if (Math.Abs(aspectRatioClient - aspectRatioLocal) > 0.05f) // Użycie progu 5% różnicy
{
Debug.WriteLine("Applying aspect ratio adjustment to Y coordinate.");
float adjustmentFactor = aspectRatioClient / aspectRatioLocal;
normalizedY *= adjustmentFactor;
// Zabezpieczenie przed zbyt małą wartością Y (np. minimalny próg)
float minThreshold = 0.01f * adjustmentFactor;
if (normalizedY < minThreshold)
{
normalizedY = minThreshold; // Minimalny próg wartości Y, dynamiczny
}
Debug.WriteLine($"Adjusted normalized Y: {normalizedY}");
}
else
{
Debug.WriteLine("Aspect ratios are very similar. No adjustment needed.");
}
// Debugowanie po korekcie proporcji
Debug.WriteLine($"Adjusted normalized Y (after checking): {normalizedY}");
// Przeliczenie współrzędnych na ekran lokalny
int xScaled = (int)(normalizedX * localWidth);
int yScaled = (int)(normalizedY * localHeight);
// Debugowanie - Współrzędne lokalne
Debug.WriteLine($"Scaled coords (local): ({xScaled}, {yScaled})");
// Przeliczenie współrzędnych na zakres 0–65535 (InputSimulator wymaga takich wartości)
int xAbsolute = (int)(normalizedX * 65535);
int yAbsolute = (int)(normalizedY * 65535);
// Debugowanie - Współrzędne absolutne
Debug.WriteLine($"Absolute coords: ({xAbsolute}, {yAbsolute})");
// Symulacja ruchu myszki
if (eventType == "move")
{
inputSimulator.Mouse.MoveMouseTo(xAbsolute, yAbsolute);
}
// Kliknięcie myszką
if (eventType == "down" && isLeftButton && isPressed)
{
inputSimulator.Mouse.MoveMouseTo(xAbsolute, yAbsolute);
inputSimulator.Mouse.LeftButtonDown();
}
// Zwolnienie przycisku
if (eventType == "up" && isLeftButton && !isPressed)
{
inputSimulator.Mouse.LeftButtonUp();
}
}Editor is loading...
Leave a Comment