您的位置:首页 > 编程语言 > C#

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

2014-03-25 15:19 976 查看
using System;<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
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
        );        
 
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: