- KEYPRESS
- When a windowed control receives a key-press message (WM_CHAR) from Windows, its message handler calls the DoKeyPress method.
说明: 响应 WM_CHAR 消息, 不包括一些功能键, 如: F1,SHIFT 键等
- KEYDOWN
- When a windowed control receives a key-down message (WM_KEYDOWN) from Windows, its message handler calls the DoKeyDown method.
响应 WM_KEYDOWN 消息
一个是按下去, 一个是按下放上来时
- procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
- begin
- // 只能触发单键事件
- end;
- procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- begin
- // 在 keyDown 事件里可以触发 shift+A 等组合键事件
- end;
Drate 回答正确, 其它人都没搞清楚, 那是 OnKeyUp! 其实响应 WM_CHAR 就是按下字符键时激发, 而按下其他功能键无效!
- procedure WMChar(var Message: TWMChar); message WM_CHAR;
- procedure TWinControl.WMChar(var Message: TWMChar);
- begin
- if not DoKeyPress(Message) then inherited;
- end;
- procedure WMKeyDown(var Message: TWMKeyDown); message WM_KEYDOWN;
- procedure TWinControl.WMKeyDown(var Message: TWMKeyDown);
- begin
- if not DoKeyDown(Message) then inherited;
- end;
来源: http://www.bubuko.com/infodetail-2944656.html