c# - Simulate mouse input on touchscreen without handicapping user input - Stack Overflow

I am currently developing a C# .NET console application on my computer which allows me to move a virtua

I am currently developing a C# .NET console application on my computer which allows me to move a virtual joystick by moving my mouse to the joystick and pressing down(currently not implemented) and moving the mouse up and down to move forward etc. (in any game like Brawl Stars, etc.). I set up a Samsung Flow smartphone screen, which allows me to access my phone from my computer, and I created a script that moves my mouse to the position of the joystick.

However, I now have the problem that I can't use my mouse while the program is running because it is constantly being "teleported" to the joystick. Additionally, I want to do the same with another joystick, but obviously, I can't have two cursors.

So, how can I simulate mouse movement and clicking without having to give up control of my real cursor?

Here is the code I'm currently using:

[DllImport("user32.dll")]
static extern short GetAsyncKeyState(int vKey);

[DllImport("user32.dll")]
static extern bool SetCursorPos(int X, int Y);

const int VK_W = 0x57;
const int VK_S = 0x53;
const int VK_A = 0x41;
const int VK_D = 0x44;
const int VK_P = 0x50;

static bool running = false;

static void Main()
{
    Console.WriteLine("Press 'P' to start/stop the process.");

    while (true)
    {
        if (GetAsyncKeyState(VK_P) < 0)
        {
            running = !running;
            Console.WriteLine(running ? "Process started." : "Process stopped.");
            Thread.Sleep(500);
        }

        if (running)
        {
            walk();
        }

        Thread.Sleep(100);
    }
}

static void walk()
{
    int x = 0;
    int y = 0;

    if (GetAsyncKeyState(VK_W) < 0)
    {
        y += 132;
    }

    if (GetAsyncKeyState(VK_S) < 0)
    {
        y -= 132;
    }

    if (GetAsyncKeyState(VK_A) < 0)
    {
        x -= 132;
    }

    if (GetAsyncKeyState(VK_D) < 0)
    {
        x += 132;
    }

    SetCursorPos(295 + x, 823 + y);
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743754588a4501526.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信