Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid window getting focus

Tags:

winapi

delphi

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 ?

like image 458
opc0de Avatar asked Nov 14 '11 16:11

opc0de


People also ask

How do I permanently turn off focus assist?

Press the Windows key, search for and open the Settings app. From the “settings” app click on “System” in the left sidebar and open “Focus Assist”. From there scroll down and either disable or configure all automatic rules so they don't turn on Focus Assist again.

How do I keep my window focused?

Just press CTRL + SPACE on whatever window you want to stay on top. If it does not match mine, when you right-click, choose Open with and Choose another app.

Why does my focus assist keeps turning on?

Focus assist (also called quiet hours in earlier versions of Windows 10) allows you to avoid distracting notifications when you need to stay focused. It's set by default to activate automatically when you're duplicating your display, playing a game, or using an app in full screen mode.

What is Windows focus stealing?

In computing, focus stealing is a mode error occurring when a program not in focus (e.g. minimized or operating in background) places a window in the foreground and redirects all keyboard input to that window.


2 Answers

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.

like image 186
Jerry Gagnon Avatar answered Oct 15 '22 17:10

Jerry Gagnon


The only method I've seen to do what you want is to disable the window with the virtual keyboard EnableWindow(hWnd, FALSE).

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

  • The easy one: Use WM_SETCURSOR. It is sent even to disabled windows, and in the high-order word of lParam you have the identifier of the original message (WM_LBUTTONDOWN, etc.). The coordinates of the cursor can be read using GetMessagePos().
  • The cool one: Use a windows hook: SetWindowsHookEx(WH_MOUSE, ...). You'll have full control of your mouse messages.
like image 44
rodrigo Avatar answered Oct 15 '22 18:10

rodrigo