глобальная передача нажатия клавиш в активное окно

Всем привет. подскажите пожалуйста, есть ли простой способ имитировать нажатия клавиш в активном окне, при свернутой программе(использую WPF)? пробовал через autoIt, но работает через раз. или все же придется копаться в WinAPI?

public void Horisonter(string value, int speed = 10, int latency = 100)
{
    Point horisontPosition = Inventory.horisontPoint;
    List<Point> pointsOfInventory = HorisontOrb.points;

    AutoItX.WinActivate("Path of Exile");
    System.Threading.Thread.Sleep(500);

    AutoItX.MouseMove((int)horisontPosition.X, (int)horisontPosition.Y, speed);
    System.Threading.Thread.Sleep(latency);

    AutoItX.MouseClick("right");
    System.Threading.Thread.Sleep(50);

    AutoItX.Send("{SHIFTDOWN}");

    string allMapList = string.Empty;
    string IsContainValue = string.Empty;

    string mapCurrent = string.Empty;


    int counts = 0;
    int countsInside = 0;
    for (int i = 0; i < 10; i++)
    {
        AutoItX.MouseMove((int)pointsOfInventory[i].X, (int)pointsOfInventory[i].Y, speed);
        System.Threading.Thread.Sleep(latency); //задержка сервера


        AutoItX.Send("^c");


        mapCurrent = Clipboard.GetText();

        if (mapCurrent == "asd")
            goto EndHorisonting;

        if (currKeysPressed.Contains("Escape") || currKeysPressed.Contains("Subtract"))
        {
            currKeysPressed = string.Empty;
            goto EndHorisonting;
        }

        if (mapCurrent.Contains(value))
        {
            AutoItX.ClipPut("asd");
            mapCurrent = "";
            continue;
        }
        while (!mapCurrent.Contains(value))
        {
            AutoItX.MouseClick("left");
            System.Threading.Thread.Sleep(latency); //задержка сервера                    

            AutoItX.Send("^c");

            mapCurrent = AutoItX.ClipGet();

            if (mapCurrent.Contains(value))
            {
                AutoItX.ClipPut("asd");
                countsInside++;
                break;
            }

            if (currKeysPressed.Contains("Escape") || currKeysPressed.Contains("Subtract"))
            {
                currKeysPressed = string.Empty;
                goto EndHorisonting;
            }
        }
        counts++;
    }

    EndHorisonting:;

    AutoItX.Send("{SHIFTUP}");
    MessageBox.Show($"counts={counts.ToString()}\n\n countsinside={countsInside.ToString()}");
}

Ответы (0 шт):