Recent

Author Topic: how to stop space key activating button  (Read 3552 times)

manusiatidakbiasa

  • Newbie
  • Posts: 2
how to stop space key activating button
« on: January 17, 2014, 12:51:59 pm »
Hi, I've been using Lazarus for sometime, but when to hiatus for a while. When I come back, I forgot my old username so I create a new one.

I need help btw

My form is a label and six button. When I type, it's put it on label and search in db for data, put search result on those six buttons and then I choose button using arrow key and press enter to activate. So far everything works OK, with only one small problem : whenever I type space, it activate a button

how do I prevent it?

some info : it's a 1 form application, I also use key preview

Thanks in advance

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: how to stop space key activating button
« Reply #1 on: January 17, 2014, 01:15:12 pm »
Spacebar presses the active (selected) button. You can try to set ActiveControl to another one or  Key := 0 on OnMouseDown event handler (KeyPreview on).

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: how to stop space key activating button
« Reply #2 on: January 17, 2014, 01:38:37 pm »
Space is used to emulate a click on the focused control be it button check box or what ever. If you do not want the button to be activated with the space then focus something else like an edit box perhaps? Enter is used to activate the default button which in most cases is the focused one but it can be unfocused as well unless the focused control is handling it aka it is a memo button or what ever has an internal handler for the enter key. in short
local handler take presents if not handled form handler take care of it if not handled there the actionlists and action along with the menus and every imaginable short cut you have added will handle it if nothing handles it the it is discarded or passed back to the system to handle it.
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

manusiatidakbiasa

  • Newbie
  • Posts: 2
Re: how to stop space key activating button <SOLVED>
« Reply #3 on: January 17, 2014, 03:01:26 pm »
Thanks.
Form Keydown event and setting up key to 0 works on my case

it was a simple application, nothing else beside that label and six buttons
so I won't have to worry about focus or anything, but I can't move focus from button because expected behaviour is first button have default focus and will be activated by pressing enter key.

Cased Solved :)

 

TinyPortal © 2005-2018