有键按下 -> 产生onKeyDown事件 -> 如果是有ASCII码的按键, 则产生onKeyPress事件
shift 是一个集合变量。type TShiftState = set of (ssShift, ssAlt, ssCtrl, ssLeft, ssRight, ssMiddle, ssDouble);
Value Meaning
ssShift The Shift key is held down.
ssAlt The Alt key is held down.
ssCtrl The Ctrl key is held down.
ssLeft The left mouse button is held down.
ssRight The right mouse button is held down.
ssMiddle The middle mouse button is held down.
ssDouble The mouse was double-clicked.
有键释放 -> 产生onKeyUp事件
onkeydown和onkeypress的区别是有些键Shift、Ctrl、Alt、F1、F2、...等按键是不会产生onKeyPress事件的
如键盘的↑键onkeypress不会响应事件,但用onkeydown就可以响应
OnKeyPress 只能抓到数值或字母按键及 Esc键、空白键,但不含功能键(F1-F12)
OnKeyDown 能抓到所有的键(除 Tab 键)但不能分辨「对称键」的不同
OnShortCut 能抓到所有的键(含 Tab 键)且能分辨「对称键」的不同
注:「对称键」指的是左右两边皆有的键,如「Enter」、「Shift」、「Ctrl」、「Alt」等等
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if ssCtrl in shift then
ShowMessage('ssCtrl');
shift 是一个集合变量。type TShiftState = set of (ssShift, ssAlt, ssCtrl, ssLeft, ssRight, ssMiddle, ssDouble);
Value Meaning
ssShift The Shift key is held down.
ssAlt The Alt key is held down.
ssCtrl The Ctrl key is held down.
ssLeft The left mouse button is held down.
ssRight The right mouse button is held down.
ssMiddle The middle mouse button is held down.
ssDouble The mouse was double-clicked.
//==============================================================================
// 去掉按回车键登录的声音
//==============================================================================
procedure TFormLogin.FormKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then
Key := #0;
end;
说明:如果不想听到操作后的系统声音,并且如果不使用Shift、Ctrl、Alt、F1、F2、...等按键使用keypress