A way to achieve this by programming in Delphi is to use Hooks(Hooks
in English).
Consider the following example(tested on Delphi XE4, Visual application):
{ Anula o funcionamento da tecla Esc }
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs;
type
tagKBDLLHOOKSTRUCT = record
vkCode: DWord;
scanCode: DWord;
flags: DWord;
time: DWord;
dwExtraInfo: PDWord;
end;
TKBDLLHOOKSTRUCT = tagKBDLLHOOKSTRUCT;
PKBDLLHOOKSTRUCT = ^TKBDLLHOOKSTRUCT;
type
TForm1 = class(TForm)
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
khk: HHOOK;
implementation
{$R *.dfm}
function KeyboardHookProc(Code: Integer; wParam : WPARAM; lParam : LPARAM): NativeInt; stdcall;
var
p:PKBDLLHOOKSTRUCT;
begin
p := PKBDLLHOOKSTRUCT(lParam);
if (Code = HC_ACTION) and (wParam = $0100) then
if (p.vkCode = VK_ESCAPE) then
Result := 1 else Result := CallNextHookEx(0, Code, wParam, lParam);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
khk := SetWindowsHookEx(13, KeyboardHookProc, hInstance, 0);
if khk = 0 then ShowMessage('Error on start hook')
else ShowMessage('Hook started');
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
UnhookWindowsHookEx(khk);
end;
end.
This will install a hook(hook) in the system to intercept the key Esc Once done, we may alter your behavior, such as overriding.
Now another example(Console App) which cancels the operation of the key combination Alt + Tab.
{ Anula o funcionamento da combinação de teclas Alt + Tab }
program Project2;
{$APPTYPE CONSOLE}
uses
Windows;
type
tagKBDLLHOOKSTRUCT = record
vkCode: DWord;
scanCode: DWord;
flags: DWord;
time: DWord;
dwExtraInfo: PDWord;
end;
TKBDLLHOOKSTRUCT = tagKBDLLHOOKSTRUCT;
PKBDLLHOOKSTRUCT = ^TKBDLLHOOKSTRUCT;
var
khk: HHOOK;
MSG: tmsg;
function KeyboardHookProc(Code: Integer; wParam : WPARAM; lParam : LPARAM): NativeInt; stdcall;
var
p:PKBDLLHOOKSTRUCT;
begin
p := PKBDLLHOOKSTRUCT(lParam);
if (Code = HC_ACTION) and (wParam = $0100) then
if (p.vkCode = VK_LMENU) or (p.flags = VK_TAB) then
Result := 1 else Result := CallNextHookEx(0, Code, wParam, lParam);
end;
begin
khk := SetWindowsHookEx(13, KeyboardHookProc, hInstance, 0);
if khk = 0 then
writeln('Error on start hook')
else
writeln('Hook started');
while GetMessage(MSG, 0, 0, 0) do begin
TranslateMessage(MSG);
DispatchMessage(MSG);
end;
UnhookWindowsHookEx(khk);
end.
to annul the Alt right-hand side use VK_RMENU*)
Aqui
(Virtual-Key Codes) you find the key code.
the documentation is in English, you know how I set up the AHK to block the ESC ?
– Alan PS
It’s been a long time since I’ve done this, I don’t remember it. But do a search, there must be some script already ready for this.
– Bacco
I couldn’t find anything to do this with the AHK, if anyone can help me....
– Alan PS
my dear, your question is very vague!
– user3628
To help those who try to answer: OP told me in the comments that wants to prevent the ESC to work in all applications, not only in the form. I commented that for this it will be better to use an AHK or something like, pq with an application in Delphi will not solve. In fact the question does not reflect well the need of the OP.
– Bacco
disable the entire system, Windows 7, 8 or Xp, if you can post q code quoted...
– Alan PS
I couldn’t just use regedit?
– Bacco
no, it needs to be a program just to change the record, I’m researching a lot but it’s hard...
– Alan PS
But regedit does this Ué. Basically it serves to query and change the record.
– Bacco
It would just run regedit, go to the key "SYSTEM Currentcontrolset Keyboard Layout" and by the desired value. If you don’t have "Scancode Map" in the list just add it, probably as a new binary value.
– Bacco
and in Vb as it does ?
– Alan PS
@DBX8 didn’t even have to open, it has several of these by the site :D http://answall.com/questions/15994/
– Bacco
@DBX8 though I don’t know what’s best, if it’s good to expect to open and close some as duplicate. There is the question, which is duplicate of which, has answer in both. Besides, if I’m not mistaken, there are more of these :)
– Bacco
@DBX8 waiting for the answer...
– Alan PS
Using AHK, folder insert this line into the script: "ESC::Return"
– Clayton A. Alves