Avoid window focus

I work on a virtual keyboard, the problem is when I press a key on the virtual keyboard, the window that needs to be sent to the data loses focus. How can i avoid this?

+8
winapi delphi
source share
4 answers

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.

+6
source share

The only method I saw to do what you want is to disable the window using the EnableWindow(hWnd, FALSE) virtual keyboard EnableWindow(hWnd, FALSE) .

Now, if the window is disabled, you will not receive mouse messages, right? You have options:

  • Easy: use WM_SETCURSOR . It is sent even to disabled windows, and in the high word lParam you have the identifier of the original message (WM_LBUTTONDOWN, etc.). The cursor coordinates can be read using GetMessagePos() .
  • Cool: use the windows hook: SetWindowsHookEx(WH_MOUSE, ...) . You will have full control over mouse messages.
+3
source share

Does it help?

 procedure WMMouseActivate(var Message: TWMMouseActivate); message WM_MOUSEACTIVATE; procedure TMyForm.WMMouseActivate(var Message: TWMMouseActivate); begin Message.Result := MA_NOACTIVATE; end; 
+1
source share

Use a class that does not have the ability to get keyboard focus, but only responds to mouse input.

Decision. Remove the virtual keyboard from TControl or TGraphicControl, not from TWinControl or TCustomControl.

+1
source share

All Articles