Call the image board to compress the image System. Diagnostics. Process = New System. Diagnostics. Process ();
Process = System. Diagnostics. process. Start ( " Mspaint.exe " , PATH );
Int Processid = Process. ID;
Automationelement Element=Findwindowbyprocessid (processid );
System. Windows. Forms. sendkeys. sendwait ("^ S");//Send Ctrl + S
System. Windows. Forms. sendkeys. sendwait ("% {F4}");//Send Alt + F4
Code Public Static Automationelement findwindowbyprocessid ( Int Processid)
{
Automationelement targetwindow = Null ;
Int Count = 0 ;
Try
{
PROCESS p = Process. getprocessbyid (processid );
Targetwindow = Automationelement. fromhandle (P. main1_whandle );
Return Targetwindow;
}
Catch (Exception ex)
{
Count ++ ;
Stringbuilder sb = New Stringbuilder ();
String Message = SB. appendline ( String . Format ( " Target window is not existing. Try # {0} " , Count). tostring ();
If (Count > 5 )
{
Throw New Invalidprogramexception (message, ex );
}
Else
{
Return Findwindowbyprocessid (processid );
}
}
}
Analog keyboard input Sendkeys. sendwait ( " {F5} " ); // Send F5 button
Sendkeys. sendwait ( " ^ S " ); // Send Ctrl + S
Sendkeys. sendwait ( " % {F4} " ); // Send Alt + F4
// press Code
backspace {backspace}, {BS }, or {bksp}
break {break}
Caps Lock {capslock}
Del or delete {Delete} or {del}
down arrow {down}
end {end}
enter {enter} or ~
ESC {ESC}
help {help}
Home {home}
ins or insert {insert} or {ins}
left arrow {left}
Num Lock {numlock}
page down {pgdn}
page up {pgup}
Print Screen {prtsc}
right arrow {right}
Sendkeys. sendwait ("+ {Tab}");
Sendkeys. sendwait ("% F");//Alt + F
Sendkeys. sendwait ("{Tab}");
Sendkeys. sendwait ("{Enter}")
//Code for multiple buttons
//To specify duplicate keys, use the {key number} format. A space must be placed between the key and number.//For example, {left 42} Means 42 times to press the left arrow key; {H 10} means 10 times to press the H key.
Where is the system. Windows. Automation
The uiautomationclient. dll is located in this folder:
C: \ Program Files \ reference assemblies \ Microsoft \ framework \ V3.0
If you can't find in your add reference->. net tab, then you have to use the Browse tab to go to the given path, and add the Assembly (right click on the references, choose add reference, Click Browse tab ):
Download demo