delphi2010:按键 控制键 组合键的判断 响应

在delphi根据TshiftState值来判断用户按下Ctrl,shift,alt等键的方法

procedure TForm1.FormMouseDown(Sender:TObject; Button: TMouseButton;
Shift:TShiftState; X, Y: Integer);
begin
if ssCtrl in shift then
ShowMessage('ssCtrl');

shift 是一个集合变量。type TShiftState = setof (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.

 

delphi中如何响应键盘的组合键(如:ctrl k),

var Hot: boolean;
procecure form1.formkeydown(.....);
begin
if (key = VK_K) and (ssShift in shift) then
if hot then
begin
//处理ctrl kk
hot := false;
end
else hot := true
else
hot := false;
end;


可以设置快捷键,也可以在程序中设置,如上

set Form1.KeyPreview totrue.

procedure TForm1.FormKeyDown(Sender:TObject; var Key: Word;
Shift: TShiftState);
begin
if (ssCtrl in Shift) and (Char(Key) in ['K', 'k']) then
ShowMessage('Ctrl K');
end;
一般的onkeydown就可以了
最好是设置一个全局的热键,系统中的任何地方都可以响应到:
下面这个帖子里很多:看看,帮助很大:


http://delphibbs.com/delphibbs/dispq.asp?lid=2285891

(from:http://hi.baidu.com/jangill/blog/item/2cf3c782a9d73498f703a6a7.html)


你可能感兴趣的:(Delphi,组合键)