说明是小键盘 囧了解详细情况要查msdn WM_KEYDOWN Message The WM_KEYDOWN message is posted to the window with the keyboard focus when a nonsystem key is pressed. A nonsystem key is a key that is pressed when the ALT key is not pressed.ParameterswParam Specifies the virtual-key code of the nonsystem key.lParam Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag, as shown in the following table.消息参数lParam包括扩展键的标志,0x1000000字位上就表示是否为小键盘。
if(event.keyCode==13)
event.keyCode=9;
</script>
if (e.KeyCode == System.Windows.Forms.Keys.Enter)
{
//发送TAB键
System.Windows.Forms.SendKeys.Send("{TAB}");
}
public class KeyFilter : IMessageFilter
{
#region IMessageFilter Members
const int WM_KEYDOWN = 0x0100;
const int VK_RETURN = 13;
private Form parent;
public KeyFilter(Form parent)
{
this.parent = parent;
} public bool PreFilterMessage(ref Message m)
{
switch (m.Msg)
{
case WM_KEYDOWN:
if (VK_RETURN != ((int)m.WParam & 0xff)) return false;
if (!(parent.ActiveControl is TextBox)) return false;
if (((int)m.LParam & 0x1000000) != 0)
{
//MessageBox.Show("小键盘回车");
SendKeys.Send("{TAB}");
return true; // 过滤
}
else
{
//MessageBox.Show("大键盘回车");
}
break;
}
return false;
}
#endregion
}private void Form1_Load(object sender, EventArgs e)
{
Application.AddMessageFilter(new KeyFilter(this));
}private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Return)
{
System.Windows.Forms.SendKeys.Send("{Tab}");
}
}============================================================================
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (Conv)
{
e.KeyChar = Convert.ToChar(9);
}
} bool Conv = false;
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
Conv = false;
if (e.KeyCode == Keys.Return)
{
Conv = true;
}
}
打错误了,不好意思,应更正应为同3楼的代码:e.KeyCode == System.Windows.Forms.Keys.Enter
{
//MessageBox.Show("小键盘回车");
SendKeys.Send("{TAB}");
return true; // 过滤
}
这个条件为真 说明什么啊。
WM_KEYDOWN Message
The WM_KEYDOWN message is posted to the window with the keyboard focus when a nonsystem key is pressed. A nonsystem key is a key that is pressed when the ALT key is not pressed.ParameterswParam
Specifies the virtual-key code of the nonsystem key.lParam
Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag, as shown in the following table.消息参数lParam包括扩展键的标志,0x1000000字位上就表示是否为小键盘。
((int)m.WParam & 0xff)),是把高位都置零是把
假如不先((int)m.WParam & 0xff)),直接跟VK_RETURN 比较,那样什么情况下会出错