I have created a WinForms app, and put a button in it.
I want to code an event, that whenever I click the button it will automatically simulate an ALT + 2 key press on the keyboard.
How can I do this?
I have created a WinForms app, and put a button in it.
I want to code an event, that whenever I click the button it will automatically simulate an ALT + 2 key press on the keyboard.
How can I do this?
.Net have a class in System.Windows.Forms
namespace that's called SendKeys
.
It allows you to send keys to mimic keyboard hits.
You need a reference to System.Windows.Forms.dll (Note: this does not have to be a winforms application for that), and then you can simply use SendKeys.Send(%2)
to mimic a user pressing alt+2.
A full list of supported special keys can be found in the msdn page I've linked to.