I want an application that when pressing a button, the keys Alt + F4 are automatically pressed to close for example the form (it would be easier to close it by code and not having two keys pressed, but it is an example).
In short, SendKeys does not work for me because I press the button and the form does not close:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Form1_DoubleClick(object sender, EventArgs e)
{
SendKeys.Send("%{F4}");
}
private void button1_Click(object sender, EventArgs e)
{
System.Windows.Forms.SendKeys.SendWait("%{F4}");
}
}
'
It does not work for me in any of the two ways, so I'm just trying to close the window or double-click on the form or click on the button. But it is not doing the keystrokes. I have tried something as simple as double-clicking the ENTER key to press the button, but it does not work either.
Greetings.