procedure TForm7.FormShortCut(var Msg: TWMKey; var Handled: Boolean); var   aKey: TShortCut;   aShift : TShiftState;   i:integer; begin   aShift:=KeyDataToShiftState(Msg.KeyData);

  i:=msg.CharCode;

  if (ssAlt in ashift)and (i=115)  then   halt;

end;

 

 

 

https://yq.aliyun.com/articles/527004

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

 
技术小甜 2017-11-16 19:22:00 浏览105 评论0

摘要: 在delphi根据TshiftState值来判断用户按下Ctrl,shift,alt等键的方法 procedure TForm1.FormMouseDown(Sender:TObject; Button: TMouseButton;Shift:TShiftState; X, Y: Integer); begin if ssCtrl in shift thenShowMessage('ssCtrl'); shift 是一个集合变量。

在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就可以了
最好是设置一个全局的热键,系统中的任何地方都可以响应到:
下面这个帖子里很多:看看,帮助很大: