标题:C#keybd_event使用为什么只能按下一个键值 怎么才能执行组合键 代码如下
只看楼主
夜龙魂
Rank: 2
等 级:论坛游民
帖 子:130
专家分:65
注 册:2009-9-24
结帖率:57.14%
已结贴  问题点数:10 回复次数:3 
C#keybd_event使用为什么只能按下一个键值 怎么才能执行组合键 代码如下
public partial class Form1 : Form
    {
        [DllImport("user32.dll", EntryPoint = "keybd_event")]
        public static extern void keybd_event(
            int bVk,
            byte bScan,
            int dwFlags,
            int dwExtraInfo
        );

        const int MOUSEEVENTF_MOVE = 0x0001;      //移动鼠标
        const int MOUSEEVENTF_LEFTDOWN = 0x0002; //模拟鼠标左键按下
        const int MOUSEEVENTF_LEFTUP = 0x0004; //模拟鼠标左键抬起
        const int MOUSEEVENTF_RIGHTDOWN = 0x0008; //模拟鼠标右键按下
        const int MOUSEEVENTF_RIGHTUP = 0x0010; //模拟鼠标右键抬起
        const int MOUSEEVENTF_MIDDLEDOWN = 0x0020; //模拟鼠标中键按下
        const int MOUSEEVENTF_MIDDLEUP = 0x0040;// 模拟鼠标中键抬起
        const int MOUSEEVENTF_ABSOLUTE = 0x8000; //标示是否采用绝对坐标


        public Form1()
        {
            InitializeComponent();
            int X = 100;
            int Y = 100;

            X += 10;
            Y += 65;

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //keybd_event(Convert.ToInt32(Keys.Control), 0, 0, 0);
            //keybd_event(Convert.ToInt32(Keys.Alt), 0, 0, 0);
            //keybd_event(Convert.ToInt32(Keys.L), 0, 0, 0);
            keybd_event(Convert.ToInt32(Keys.Alt), 0, 0, 0);
            keybd_event(Convert.ToInt32(Keys.F4), 0, 0, 0);
            keybd_event(Convert.ToInt32(Keys.Alt), 0, 0x2, 0);
            keybd_event(Convert.ToInt32(Keys.F4), 0, 0x2, 0);
            this.Close();
        }

    }
搜索更多相关主题的帖子: event keybd 代码 
2010-09-03 14:58
烟雨袅袅
Rank: 6Rank: 6
来 自:星空雨际
等 级:侠之大者
威 望:1
帖 子:430
专家分:494
注 册:2007-11-26
得分:5 
以下是   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   +     (SHIFT="+")
  CTRL   ^     (CTRL="^") 如果输入
  ALT   %     
private void button1_Click(object sender, System.EventArgs e)
        {//英文输入
            this.richTextBox1.Focus();                                            
            for(int i=65;i<91;i++)
            {
                char Letter=(char)i;
                SendKeys.Send(Letter.ToString());
                System.Threading.Thread.Sleep(100);        
                SendKeys.Flush();
            }        
            for(int i=97;i<123;i++)
            {
                char Letter=(char)i;
                SendKeys.Send(Letter.ToString());
                System.Threading.Thread.Sleep(100);
                SendKeys.Flush();
            }        
        }
        private void button3_Click(object sender, System.EventArgs e)
        {//数字输入
            this.richTextBox1.Focus();                                            
            for(int i=0;i<10;i++)
            {               
                SendKeys.Send(i.ToString());
                System.Threading.Thread.Sleep(100);        
                SendKeys.Flush();
            }               
        }
        private void button4_Click(object sender, System.EventArgs e)
        {//Backspace
            this.richTextBox1.Focus();
            SendKeys.Send("{Backspace}");        
        }
        private void button5_Click(object sender, System.EventArgs e)
        {//Home
            this.richTextBox1.Focus();
            SendKeys.Send("{Home}");               
        }
        private void button6_Click(object sender, System.EventArgs e)
        {//End
            this.richTextBox1.Focus();
            SendKeys.Send("{End}");        
        }
        private void button7_Click(object sender, System.EventArgs e)
        {//Enter
            this.richTextBox1.Focus();
            SendKeys.Send("{Enter}");        
        }
        private void button8_Click(object sender, System.EventArgs e)
        {//Delete
            this.richTextBox1.Focus();
            SendKeys.Send("{Delete}");        
        }
        private void button2_Click(object sender, System.EventArgs e)
        {//Shift+Home
            this.richTextBox1.Focus();
            SendKeys.Send("+{Home}");               
        }
        private void button9_Click(object sender, System.EventArgs e)
        {//Shift+End
            this.richTextBox1.Focus();
            SendKeys.Send("+{End}");               
        }
 看下方法的说明
public class SendKeys : System.Object
    System.Windows.Forms 的成员
摘要:
 提供将键击发送到应用程序的方法。   
public static void Send ( System.String keys )
    System.Windows.Forms.SendKeys 的成员
摘要:
 向活动应用程序发送击键。   
public static void Sleep ( System.TimeSpan timeout )
    System.Threading.Thread 的成员
摘要:
 将当前线程阻塞指定的时间。   
public static void Flush (  )
    System.Windows.Forms.SendKeys 的成员
转自http://www.
2010-09-03 15:12
夜龙魂
Rank: 2
等 级:论坛游民
帖 子:130
专家分:65
注 册:2009-9-24
得分:0 
能详细说明怎么使用组合键吗
2010-09-06 10:57



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-317640-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.303074 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved