Avoid window getting focus

后端 未结 4 1562
忘了有多久
忘了有多久 2021-01-02 13:25

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

4条回答
  •  半阙折子戏
    2021-01-02 14:10

    When your keyboard form receives focus, part of the message it receives is the handle of the window that lost focus (wParam). Do what you need to do and set the focus back to the window that lost focus.

    EDIT: See the documentation on WM_SETFOCUS

    EDIT 2:

    Also, you could use the following when creating your custom form:

    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 activating (taking focus from the other form). Like I alluded to in my comment, you should probably be using non-windowed controls for keys.

提交回复
热议问题