Author: Tomas Rutkauskas
SetCapture directs all mouse events to a specific window. Is there a similar API
for the keyboard? Can this be accomplished without using hooks? I want to track
what the user presses on the keyboard and mouse and allow or reject the events.
Answer:
Look up TApplication.OnMessage and study the example given, then look at the
example below:
1 2 procedure TMainForm.AppMessage(var Msg: TMsg; var Handled: Boolean);
3 const4 BLOCKEDKEYS = [VK_TAB, VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT, VK_SPACE];
5 begin6 if (Msg.message = WM_KEYDOWN) then7 begin8 if (Msg.wParam in BLOCKEDKEYS) then9 begin10 Handled := True;
11 end;
12 end;
13 end;