When your keyboard shape receives focus, part of the received message is a handle to the window that has lost focus (wParam). Do what you need and set the focus back to the window that lost focus.
EDIT: see the documentation for WM_SETFOCUS
EDIT 2:
In addition, when creating a custom form, you can use the following:
procedure TMainForm.CreateParams(var Params: TCreateParams) ; //const WS_EX_NOACTIVATE = $8000000; begin inherited; Params.ExStyle := Params.ExStyle + WS_EX_NOACTIVATE; end;
To prevent your form from being activated (focus from another form). As I mentioned in my comment, you should probably use non-window controls for keys.
Jerry gagnon
source share