Jump to content
Ian Branch

Capture Ctrl-Click on a TButton?

Recommended Posts

Hi Team,

I have a TButton that does one thing, I want to capture a Ctrl-Click on that button so I can have it do some preprocessing before continuing.

How can I do that please?

 

Regards & TIA,

Ian

Share this post


Link to post
13 hours ago, dummzeuch said:

Use a normal OnClick event and check whether the Ctrl key is currently pressed. That's the only way I know.

Alternatively, the OnMouse(Down|Up) events have a Shift parameter which defines several flags, including ssCtrl, which is present when the Ctrl key is down when the event is triggered.

 

Share this post


Link to post

if the "Button" is focused, you can use its events togheter with mouse-click too

  • but  "GetKeyState(VK_CONTROL) < 0";  is better, of course!
var
  LText: string;

procedure TForm1.Button1Click(Sender: TObject);
begin
  caption := LText + ' OnClick - 2º';
end;

procedure TForm1.Button1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  LText := Key.ToString; // Ctrl = 17
end;

procedure TForm1.Button1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  LText := 'no key pressed';
end;

procedure TForm1.Button1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  caption := LText + ' OnMouseDown - 1º';
end;

 

Edited by programmerdelphi2k

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×