首页 > 其他 > 详细

keydown和KeyPress事件有何不同

时间:2019-02-04 11:38:48      阅读:219      评论:0      收藏:0      [点我收藏+]

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;

keydown和KeyPress事件有何不同

原文:https://www.cnblogs.com/jijm123/p/10351562.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!