1. 程式人生 > >keydown和KeyPress事件有何不同

keydown和KeyPress事件有何不同

send tro hand its 就是 nbsp control res 組合鍵

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事件有何不同