using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
//引入命名空间。
using System.Diagnostics;
using Microsoft.VisualBasic.Devices;//添加此命名空间前,必须添加引用->Microsoft.VisualBasic.dll
namespace WindowsApplication1
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
/**
* CALC.EXE 计算器
* notepad.EXE 记事本
**/
private void btnSendKeyToCal_Click(object sender, EventArgs e)
{
Process myProcess = System.Diagnostics.Process.Start("notepad.EXE");
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
//先等待,知道目标程序已经准备好输入...
myProcess.WaitForInputIdle(1000);
if (myProcess.Responding)
{
//传送按键.
SendKeys.SendWait("10");
SendKeys.SendWait("*");
SendKeys.SendWait("10");
SendKeys.SendWait("=");
SendKeys.SendWait("100");
SendKeys.SendWait("A");
SendKeys.SendWait("B");
SendKeys.SendWait("C");
SendKeys.SendWait("D");
SendKeys.SendWait("E");
SendKeys.SendWait("F");
SendKeys.SendWait("G");
SendKeys.SendWait("H");
SendKeys.SendWait("I");
SendKeys.SendWait("J");
SendKeys.SendWait("K");
SendKeys.SendWait("L");
SendKeys.SendWait("M");
SendKeys.SendWait("N");
SendKeys.SendWait("O");
SendKeys.SendWait("P");
SendKeys.SendWait("Q");
}
}
private void button1_Click(object sender, EventArgs e)
{
Process myProcess = System.Diagnostics.Process.Start("CALC.EXE");
Computer myComputer = new Computer();
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
//先等待,知道目标程序已经准备好输入...
myProcess.WaitForInputIdle(1000);
if (myProcess.Responding)
{
//传送按键.
myComputer.Keyboard.SendKeys("110",true);
myComputer.Keyboard.SendKeys("/", true);
myComputer.Keyboard.SendKeys("110", true);
myComputer.Keyboard.SendKeys("=", true);
myComputer.Keyboard.SendKeys("*", true);
myComputer.Keyboard.SendKeys("3", true);
myComputer.Keyboard.SendKeys("=", true);
}
}
}
}
-------------------------------------------------
改动一下,变成启动qq2009,自动输入密码,登陆。(只按一个键~~~)
附件:
-------------------------------------------------------
C# SendKeys的一些特殊键代码表。
键 代码
BACKSPACE {BACKSPACE}、{BS} 或 {BKSP}
BREAK {BREAK}
CAPS LOCK {CAPSLOCK}
DEL 或 DELETE {DELETE} 或 {DEL}
DOWN ARROW(下箭头键) {DOWN}
END {END}
ENTER {ENTER} 或 ~
ESC {ESC}
HELP {HELP}
HOME {HOME}
INS 或 INSERT {INSERT} 或 {INS}
LEFT ARROW(左箭头键) {LEFT}
NUM LOCK {NUMLOCK}
PAGE DOWN {PGDN}
PAGE UP {PGUP}
PRINT SCREEN {PRTSC}(保留,以备将来使用)
RIGHT ARROW(右箭头键) {RIGHT}
SCROLL LOCK {SCROLLLOCK}
TAB {TAB}
UP ARROW(上箭头键) {UP}
F1 {F1}
F2 {F2}
F3 {F3}
F4 {F4}
F5 {F5}
F6 {F6}
F7 {F7}
F8 {F8}
F9 {F9}
F10 {F10}
F11 {F11}
F12 {F12}
F13 {F13}
F14 {F14}
F15 {F15}
F16 {F16}
数字键盘加号 {ADD}
数字键盘减号 {SUBTRACT}
数字键盘乘号 {MULTIPLY}
数字键盘除号 {DIVIDE}
若要指定与 SHIFT、CTRL 和 ALT 键的任意组合一起使用的键,请在这些键代码之前加上以下一个或多个代码:
键 代码
SHIFT +
CTRL ^
ALT %