Ian Branch 127 Posted April 29, 2023 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
dummzeuch 1505 Posted April 29, 2023 Use a normal OnClick event and check whether the Ctrl key is currently pressed. That's the only way I know. function IsControlKeyPressed: Boolean; begin Result := GetKeyState(VK_CONTROL) < 0; end; Source: https://tips.delphidabbler.com/tips/45 Share this post Link to post
programmerdelphi2k 237 Posted April 29, 2023 (edited) nevermind ... sorry Edited April 29, 2023 by programmerdelphi2k Share this post Link to post
Remy Lebeau 1398 Posted April 29, 2023 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
programmerdelphi2k 237 Posted April 29, 2023 (edited) 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 April 29, 2023 by programmerdelphi2k Share this post Link to post