我有一个panel1_Paint用于在panel2_Paint中绘制显示。我正在像这样从form_KeyPress阅读键盘。
private void form_KeyPress(object sender, KeyPressEventArgs e)
{
scankeyinput3 += e.KeyChar.ToString();
if (scankeyinput3 != "") { scankeyinput4 = ""; }
if (keyboardInputLength2 >= 1)
{
scankeyinput4 = scankeyinput3.Substring(scankeyinput3.Length - 1);
}
scankeyinput3 = scankeyinput4;
ProcessCmdKey(ref msg, keydata);
}
我正在使用ProcessCmdKey获取Form3中的键盘键。
protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
{
scankeyinput6 = keyData.ToString();
Form3.textchangedtextbox2 = 4;
if (scankeyinput6 == "None") { scankeyinput6 = "@"; }
if (scankeyinput6 == "Next") { scankeyinput6 = "@"; }
if (scankeyinput6 == "@") { Form3.textchangedtextbox2 = 0; }
if (scankeyinput6 == "#") { Form3.textchangedtextbox2 = 0; }
if (scankeyinput6 != "") { scankeyinput4 = ""; }
keyboardInputLength2 = scankeyinput6.Length;
if (keyboardInputLength2 >= 1)
{
scankeyinput4 = scankeyinput6.Substring(scankeyinput6.Length - 1);
}
scankeyinput6 = scankeyinput4;
return base.ProcessCmdKey(ref msg, keyData);
}
我遇到的问题是当我在Form3 panel1_Paint button10()中时获取键盘键。我无法在Form3 panel1_Paint button10()上获得焦点。因此,我无法从保护覆盖bool ProcessCmdKey(ref System.Windows.Forms.Message msg,System.Windows.Forms.Keys keyData)中读取键
我想知道如何在button10()上获得焦点。我用这里的代码读取键盘以返回form,Form1,Form2和From3中的键。我无法在button10()上获得焦点。
我尝试使用文本框获取密钥,但没有功能。
1条答案
按热度按时间iyfamqjs1#
从您的描述来看,您似乎希望接收“热键”类型的消息,而不管哪个窗体或控件处于焦点状态。您可以通过为主窗体实现IMessageFilter来实现此目标。