Board index » delphi » Hotkey

Hotkey

Hi there

How can one make a hotkey to work with e.g. a button, is it possible to use
any key as a hotkey ??

Thanks in advance

Farouche

 

Re:Hotkey


One easy way is to add a top menu item called shortcuts (say) with
visible property set to false. Create a sub menu item with the hotkey
selected from the list available. This menu item should simply call
the click method for the button.  Using this method you can have a
whole series of keyboard shortcuts to any action in your form.

If you do not have a menu make one with shortcuts as the main item.
The menu will be there but you won't see it.

Regards
John Collins

Quote
Farouche <a...@mail1.stofanet.dk> wrote in message

news:7mav8p$cr8$1@news101.telia.com...
Quote
> Hi there

> How can one make a hotkey to work with e.g. a button, is it possible
to use
> any key as a hotkey ??

> Thanks in advance

> Farouche

Re:Hotkey


Quote
Farouche <a...@mail1.stofanet.dk> wrote in message

news:7mav8p$cr8$1@news101.telia.com...

Quote
> Hi there

> How can one make a hotkey to work with e.g. a button, is it possible to
use
> any key as a hotkey ??

Use the form's OnKeyDown event.

const
  VK_S = $53;

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if (Shift = [ssCtrl]) and (Key = VK_S) then
    SaveButtonClick(Sender);
end;

Remember to set the form's KeyPreview property to True.

--
Jeremy Collins
Kansai Business Systems
http://www.kansai.co.uk/

Re:Hotkey


In my humble opinion, it is better to use the event designed for this
purpose: OnShortCut.... KeyPreview does not matter in that case, ShortCuts
are always handled first.  

Or, if using D4, use an ActionList, not an invisble MenuItem.  Again, that
is what ActionLists were designed for.

Also, why would you re-define a VK_ constant?  They are already defined in
Windows.pas, no?  Isn't this a potential typo nightmare?

Who put the {*word*75}y powder in my coffee?? :-P~~

HTH
-John

Quote
Jeremy Collins wrote:

> Farouche <a...@mail1.stofanet.dk> wrote in message
> news:7mav8p$cr8$1@news101.telia.com...
> > Hi there

> > How can one make a hotkey to work with e.g. a button, is it possible to
> use
> > any key as a hotkey ??

> Use the form's OnKeyDown event.

> const
>   VK_S = $53;

> procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
>   Shift: TShiftState);
> begin
>   if (Shift = [ssCtrl]) and (Key = VK_S) then
>     SaveButtonClick(Sender);
> end;

> Remember to set the form's KeyPreview property to True.

> --
> Jeremy Collins
> Kansai Business Systems
> http://www.kansai.co.uk/

Re:Hotkey


Quote
jph <j...@InternetAddress.com> wrote in message

news:378A6834.72D6BDCE@InternetAddress.com...

Quote
> In my humble opinion, it is better to use the event designed for this
> purpose: OnShortCut.... KeyPreview does not matter in that case, ShortCuts
> are always handled first.

> Or, if using D4, use an ActionList, not an invisble MenuItem.  Again, that
> is what ActionLists were designed for.

Ah, but I'm still using D3.

Quote
> Also, why would you re-define a VK_ constant?  They are already defined in
> Windows.pas, no?  Isn't this a potential typo nightmare?

No, they're not.

Quote
> Who put the {*word*75}y powder in my coffee?? :-P~~

It's called caffeine <g>

--
Jeremy Collins
Kansai Business Systems
http://www.kansai.co.uk/

Other Threads