问题是,当我按下全局热键组合(ctrl + 空格)并按住按钮一秒钟时,程序会循环它并显示很多相同的文本,例如:
“一些文本”“更多文本”“一些文本”“更多文本”“一些文本”“更多文本”
假设用户年龄较大,无法快速释放键盘按钮。如何使程序一次执行此全局热键操作?(即使热键被按下了一段时间)。我试过(uint)fsModifiers.Control | (uint)fsModifiers.Norepeat
但没有效果。提前致谢!
protected override void WndProc(ref Message keyPressed)
{
if (keyPressed.Msg == 0x0312)
{
System.Threading.Thread.Sleep(300);
System.Windows.Forms.SendKeys.Send("some text");
System.Threading.Thread.Sleep(500);
System.Windows.Forms.SendKeys.Send("{TAB}");
System.Threading.Thread.Sleep(500);
System.Windows.Forms.SendKeys.Send("{TAB}");
System.Threading.Thread.Sleep(500);
System.Windows.Forms.SendKeys.Send("some more text");
MessageBox.Show("DONE", "DONE", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
base.WndProc(ref keyPressed);
}
private void Form1_Load(object sender, EventArgs e)
{
RegisterHotKey(this.Handle, 1, (uint)fsModifiers.Control , (uint)Keys.Space);
}
public enum fsModifiers
{
Alt = 0x0001,
Control = 0x0002,
Shift = 0x0004,
Window = 0x0008,
Norepeat = 0x4000,
}