With delphi, how can I disable the ESC key for all applications?

4

I need to disable esc for all programs using Delphi.

Probably form has to be always active and I disable the key in a way similar to the example below.

My code so far:

procedure TForm2.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin

if Key = 27 then
ShowMessage('A tecla Backspace foi pressionada');

end;
    
asked by anonymous 10.05.2014 / 19:52

2 answers

7

About keyboard event recognition

If you press ESC your message does not appear as defined in your FormKeyDown method, then make sure the KeyPreview of the form was set to True .

How to undo the

Give preference to the event OnKeyPress and to cancel the do:

if key = #27 then
  key := #0;
    
11.05.2014 / 01:58
5

Alternate answer, using the record: just create a text file "anycoisa.reg" with this data:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,5b,e0,38,00,00,00,00,00

Make sure the name is qualquercoisa.reg and not qualquercoisa.reg.txt . Saving the file, double click on it, and accept the import.

  

Attention: only do this if you are sure that this will achieve the desired result.

    
15.05.2014 / 21:55