• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 163
  • Last Modified:

D1 Button Activation By Space Bar

Using Delphi 1. If the user presses the space bar, any highlighted button is activated. How do I stop this happening, so that the button is only activated when the user hits CR or clicks on the button with the mouse?
0
itoft
Asked:
itoft
  • 4
  • 3
1 Solution
 
itoftAuthor Commented:
Edited text of question
0
 
itoftAuthor Commented:
Edited text of question
0
 
rwilson032697Commented:
This is the default windows behaviour (ie: space = mouse click on active control).

You could stop it by setting form1.keypreview to true and setting an on KeyDown event for the form. Check if it is a space and that the active control is a button and nix the char if so:

       procedure TForm3.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if (key = vk_space) and (activecontrol is TButton) then // swallow it...
    key := #0;
end;

Cheers,

Raymond.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
rwilson032697Commented:
Oops, that should read:

key := 0;

Cheers,

Raymond.
0
 
itoftAuthor Commented:
Unfortunately my question was not detailed enough as my question has been answered, but it doesn't solve my problem.
I wish to disable the space=mouse click on active control when a MessageDlg object is displayed, while still being able to detect which button on the MessageDlg foorm has been pressed.
0
 
rwilson032697Commented:
This is a bit trickier. What you will need to do is implement your own messagedlg form which looks and feels the same but catches the space key as you require.

Cheer,

Raymond.
0
 
itoftAuthor Commented:
Adjusted points to 150
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now