Recent

Author Topic: how to set hotkey for button ?  (Read 10653 times)

m4u_hoahoctro

  • Full Member
  • ***
  • Posts: 160
how to set hotkey for button ?
« on: February 13, 2013, 07:50:32 am »
how to use hotkey for a button ? give me an example code
thanks

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: how to set hotkey for button ?
« Reply #1 on: February 13, 2013, 09:27:54 am »
In Object inspector, set caption:
example: 'Caption' and insert  '&' before char who you wont for Key(It's work with Alt+char, e.g. &Caption (Alt+C)).
Regards
p.s. Also, you can use TActionList with button, easy way to configure HotKey.
« Last Edit: February 13, 2013, 09:31:50 am by exdatis »

Luke Snowmaker

  • New Member
  • *
  • Posts: 11
  • "Who are you...?" -"Nobody..."
« Last Edit: February 13, 2013, 09:41:59 am by Luke Snowmaker »
openSUSE 12.2
Lazarus IDE 1.0.4/FPC 2.6.0

m4u_hoahoctro

  • Full Member
  • ***
  • Posts: 160
Re: how to set hotkey for button ?
« Reply #3 on: February 13, 2013, 01:04:56 pm »
example i want when i press enter, the button 1 will be call, can you give me code of that example ? thanks

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: how to set hotkey for button ?
« Reply #4 on: February 13, 2013, 01:14:25 pm »
Do not try to use VK_RETURN, it's event onKeyPress. Try something else, if you press enter, object in focus will be started.
Regards.
p.s. onKeyPress :
  if Key = #13 then //VK_RETURN(object's related)
  begin
    //code
  end;

SunyD

  • Guest
Re: how to set hotkey for button ?
« Reply #5 on: February 13, 2013, 02:34:20 pm »
Use Action Property. Actionlists are the best eventhandler. They handle also shortcuts. You can use only one handler for many buttons, menus ....
If you change actions caption or image property then your button or menu will renamed automically. Look further:
http://lazarus-ccr.sourceforge.net/docs/lcl/actnlist/tactionlist.html
http://lazarus-ccr.sourceforge.net/docs/lcl/actnlist/taction.html

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: how to set hotkey for button ?
« Reply #6 on: February 13, 2013, 04:54:07 pm »
To use enter as a a shortcut set the buttons default property to true and use escape set buttons cancel property to true. Only one button can be the default on a single form the same applies to cancel.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

 

TinyPortal © 2005-2018