O
O
Olegofr3n772020-08-19 15:44:22
C++ / C#
Olegofr3n77, 2020-08-19 15:44:22

How to simulate keypress c#?

There is a software in c#, its task is in def. point in time to unmount drives in VeraCrypt.
Veracrypt has hotkeys configured for unmounting (Ctrl + Q).
How can I use c# to simulate pressing these two keys? Does not work. Tried the example from the Microsoft website
SendKeys.SendWait("^{Q}");

// 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("=");
}

But I haven't found anything that works.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Olegofr3n77, 2020-08-19
@Olegofr3n77

I found the same solution, apparently the register matters and everything works fine!
SendKeys.SendWait("^{q}");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question