如何模拟键盘硬件输入 我想模拟键盘硬件输入,例如当前输入法状态是“紫光拼音输入法”,我想模拟在键盘上按下一个a键,再模拟按下空格键,然后就可以在文本框中输入一个“啊”汉字 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public class Form1 : Form{ public Form1() { InitializeComponent(); } /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.textBox1 = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(86, 129); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 0; this.button1.Text = "button1"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // textBox1 // this.textBox1.Location = new System.Drawing.Point(51, 63); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(198, 21); this.textBox1.TabIndex = 1; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(292, 266); this.Controls.Add(this.textBox1); this.Controls.Add(this.button1); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.Button button1; private System.Windows.Forms.TextBox textBox1; private void button1_Click(object sender, EventArgs e) { this.textBox1.Focus(); this.textBox1.ImeMode = ImeMode.OnHalf; SendKeys.SendWait("a "); }} 谢谢水月流影,我是想用API实现模拟键盘硬件输入,下面代码,第一次单击button1按钮时可以输入一个字母a,但是没有空格,第二次单击button1时,变成输入了一个大写的字母A了,为什么变大写了呢?难道(keybd_event(20, MapVirtualKey(20, 0), 1, 0);)不是模拟输入一个空格键吗?空格键的Virtual-Key码是20啊,这是怎么回事,请高手指教!!![DllImport("user32.dll")]public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);[DllImport("user32.dll", CharSet = CharSet.Auto)]public static extern byte MapVirtualKey(Byte bVk, int c);private void button1_Click(object sender, EventArgs e) { textBox1.Focus(); keybd_event(0x41, MapVirtualKey(0x41,0), 0, 0); keybd_event(20, MapVirtualKey(20, 0), 1, 0); } 关于C#的代码问题 DataGridView控件获取当前行(排序) 大侠们很急!C#如何实现记住密码和自动登录 在DataGridView中,如何让回车键跳到下一列 Repeater控件 如何把一个界面类做成一个控件? asp.net 弹出确认消息框 请教高手,如何用C#做后台执行的无窗口程序? 怎么判断access数据库里面是否包含某个表的名字,或者包含那些表 C#调用第三方程序,会出现提示对话框,如何自动点击确定,让程序继续执行下去 关于“.Net精简框架”的模拟键盘问题--100分 QQ登录框上的软键盘
public class Form1 : Form
{
public Form1()
{
InitializeComponent();
} /// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null; /// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region Windows Form Designer generated code /// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(86, 129);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(51, 63);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(198, 21);
this.textBox1.TabIndex = 1;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout(); } #endregion private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1; private void button1_Click(object sender, EventArgs e)
{
this.textBox1.Focus();
this.textBox1.ImeMode = ImeMode.OnHalf; SendKeys.SendWait("a ");
}
}
public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern byte MapVirtualKey(Byte bVk, int c);
private void button1_Click(object sender, EventArgs e)
{
textBox1.Focus();
keybd_event(0x41, MapVirtualKey(0x41,0), 0, 0);
keybd_event(20, MapVirtualKey(20, 0), 1, 0);
}