Disabling the BackSpace key


Please help...

How do I disable the backspace key? I want to disregard the backspace key at certain times in my application.

Many thanks.
Little_NikkiAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
BSamsonConnect With a Mentor Commented:
Set up an Event handler for KeyPress on your form and put some code like this in

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = Char(8) then
    Key := Char(0);
end;

Now, when you want to activate this code, set Form1.KeyPreview := True;

0
 
LischkeCommented:
That's quite easy. Set the form's KeyPreview to True and write an key down handler where you can reject specific keys:

procedure TMainForm.FormKeyPress(Sender: TObject; var Key: Char);

begin
  if Key = #8 then
  begin
    Key := #0;
    Close;
  end;
end;


Ciao, Mike
0
 
LischkeCommented:
Ooops, sorry, you should of course avoid calling Close :-) (I copied the sample from an ESC key handler where I want to close the form). Just set Key to #0 that's all.

Ciao, Mike
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
BSamsonCommented:
Ooops, Sorry Mike

You're a much faster typist than me. I was typing my answer as you posted your comment up.

Please reject my answer as it's identical to Mikes.

Brian
0
 
craig_capelCommented:
before i post a question up.... how possible is it do the same thing as dos did, hook on to int 9, keyboard int vector and then disable the backspace....or is this simply not possible because its windows?

if you think its possible, i will post up a question.....
0
 
LischkeCommented:
Hi Craig,

no, hooking an interrupt vector is not possible any longer. You should really get used that a system has total control of your machine (and it's not only Windows, but each modern operating system).

Ciao, Mike
0
 
Little_NikkiAuthor Commented:
Thank you so much! You've been a big help.
Til next time =)
0
 
LischkeCommented:
Nikki, if you wanna have a next time then please look more carefully who you give the points!

BSamson, now you know why I'm so often complaining about proposing an answer by default. Please, use only comments in the future...

Ciao, Mike
0
All Courses

From novice to tech pro — start learning today.