Creating keyboard shortcuts lazarus / 10-Designer ---------------------------------------------------------------------- cybersmyth · 2011-04-05 14:36 How do you go about creating a keyboard shortcut? I have a "Start" button, I'd like the user to be able to execute it with ctrl+s rather than just clicking on it. ---------------------------------------------------------------------- Leledumbo · 2011-04-05 17:54 Hmm... TButton doesn't seem to have Shortcut property, but it has Action property where its instance has Shortcut property. So you have to start designing your apps correctly (read: remove redundant code), by forwarding all requests (menus, buttons, etc) through a TAction of TActionList. ---------------------------------------------------------------------- Blaazen · 2011-04-05 21:24 Acceleration keys are not enough? Caption:='&Start'; ---------------------------------------------------------------------- typo · 2011-04-05 21:43 Code: [Select]// KeyPreview on procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin   if (Key = LCLType.VK_S) and (ssCtrl in Shift) then     ButtonStartClick(Sender); end; ---------------------------------------------------------------------- cybersmyth · 2011-04-06 13:21 The FormKeyDown method worked great after a quick tweak. Apparently you have to have the form property for "KeyPreview" set to true. Otherwise each object will to capture the keyboard. Thanks guys! ---------------------------------------------------------------------- eny · 2011-04-06 19:38 Now that you've done it the hard way, you could try leledumbo's approach and remove all redundant code: - Drop a TActionList op the form. - Add a new action to the actionlist that performs the requested action in the OnExecute method. - Set Ctrl-s as the shortcut key for this action via the Object Inspector. - Assign this action to the Start button as well. Configuration over programming!