打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
C# Winform 如何传送按键给其他应用程序【源】
C# Winform 如何传送按键给其他应用程序【源】
2009-12-12 14:19

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   %


本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
c# 模拟键盘输入 SendKeys
C#中的SendKeys发送组合键时,字母要为小字
VB.NET SendKeys方法与键入值
SendKeys 语句(VBA)
VB 编程中 SendKeys 语句的妙用
C#模拟键盘鼠标事件 - 护马 - 博客园
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服