编程论坛's Archiver

yx880502 发表于 2008-5-11 13:16

模拟键盘的一点小问题

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;

namespace Keyboard
{
    public partial class Form1 : Form
    {
        int[] kk ={67,68,69};

        public Form1()
        {
            InitializeComponent();
            this.KeyPreview = true;
            Form.CheckForIllegalCrossThreadCalls = false;
        }

        [DllImport("user32.dll")]
        static extern void keybd_event(
            byte bVk,
            byte bScan,
            uint dwFlags,
            uint dwExtraInfo
            );

        const uint KEYEVENTF_EXTENDEDKEY = 0x1;
        const uint KEYEVENTF_KEYUP = 0x2;
        public static void KeyBoardDo(int[] key)
        {
            foreach (int k in key)
            {
                keybd_event((byte)k, 0x69, KEYEVENTF_EXTENDEDKEY | 0, 0);
            }
            foreach (int k in key)
            {
                keybd_event((byte)k, 0x69, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
            }
        }
        
     
        private void Form1_KeyPress(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                Application.Exit();
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            textBox1.Focus();
            KeyBoardDo(kk);
        }
    }
}

哪位高人给我加上注释啊,尤其是keybd_event()的4个参数是什么意思
另外怎么输入组合键???

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.