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?
itoftAsked:
Who is Participating?
 
rwilson032697Connect With a Mentor Commented:
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
 
itoftAuthor Commented:
Edited text of question
0
 
itoftAuthor Commented:
Edited text of question
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.