C # Console: Use mspaint to open and save the image.

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.