Olegofr3n77
@Olegofr3n77
Love C# & PHP

Как имитировать нажатие клавиш c#?

Есть софтина на c#, ее задача в опр. момент времени размонтировать диски в VeraCrypt.
В Veracrypt настроены горячие клавиши на размонтирование (Ctrl + Q).
Как можно при помощи c# имитировать нажатие этих двух клавиш?
SendKeys.SendWait("^{Q}");
Не работает.
Пробовал пример с сайта Microsoft
// Get a handle to an application window.
[DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
public static extern IntPtr FindWindow(string lpClassName,
    string lpWindowName);

// Activate an application window.
[DllImport("USER32.DLL")]
public static extern bool SetForegroundWindow(IntPtr hWnd);

// Send a series of key presses to the Calculator application.
private void button1_Click(object sender, EventArgs e)
{
    // Get a handle to the Calculator application. The window class
    // and window name were obtained using the Spy++ tool.
    IntPtr calculatorHandle = FindWindow("CalcFrame","Calculator");

    // Verify that Calculator is a running process.
    if (calculatorHandle == IntPtr.Zero)
    {
        MessageBox.Show("Calculator is not running.");
        return;
    }

    // Make Calculator the foreground application and send it
    // a set of calculations.
    SetForegroundWindow(calculatorHandle);
    SendKeys.SendWait("111");
    SendKeys.SendWait("*");
    SendKeys.SendWait("11");
    SendKeys.SendWait("=");
}

Но так и не нашел ничего рабочего.
  • Вопрос задан
  • 1237 просмотров
Решения вопроса 1
Olegofr3n77
@Olegofr3n77 Автор вопроса
Love C# & PHP
Нашел я таки решение, видимо регистр имеет значени и при
SendKeys.SendWait("^{q}");
Все прекрасно отрабатывает!
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы