在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 = 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.

 

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

1: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;
2:可以设置快捷键,也可以在程序中设置,如上
3:set Form1.KeyPreview to true.
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;


4:一般的就楼上的onkeydown就可以了
最好是设置一个全局的热键,系统中的任何地方都可以响应到:

你可能感兴趣的:(在delphi根据TshiftState值来判断用户按下Ctrl,shift,alt等键的方法)