C# 调用API keybd_event 模拟键盘事件

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Runtime.InteropServices;

namespace WindowsFormsApplication1

{

 

 

    public partial class Form1 : Form

    {       

        public Form1()

        {

            InitializeComponent();

        }

        private void button1_Click(object sender, EventArgs e)

        {

            keybd_event((byte)Keys.CapsLock , 0, 0, 0);

            keybd_event((byte)Keys.CapsLock , 0, 2, 0);  

        }

 

 

 

        [DllImport("user32.dll", EntryPoint = "keybd_event")]

        public static extern void keybd_event(

            byte bVk,    //虚拟键值

            byte bScan,// 一般为0

            int dwFlags,  //这里是整数类型  0 为按下,2为释放

            int dwExtraInfo  //这里是整数类型 一般情况下设成为 0

        );        

 

    }

}

你可能感兴趣的:(技术文章)