Kivy on Windows10. How to click a button, when kivy application does not in focus?

Viewed 429

I have a simple kivy app with 3 buttons. When my kivy app is not in focus, I have to click on it once, in order to press any button. How can I click any button with only one click without activating a kivy window?

#:kivy 1.10.0

cannot press any button, when a window is not in focus

2 Answers

I encountered this issue recently as well. Couldn't find a solution but I did implement a workaround that worked. What I did was bound kivy.core.window.Window to on_cursor_enter to trigger a callback that brings the kivy app to foreground, gaining focus, whenever the mouse enters back into the kivy app window:

Window.bind(on_cursor_enter=mouseEnter)

def mouseEnter(instance):
    Window.raise_window()

I was inspired by Jack's answer. I have found that Window.raise_window causes the taskbar icon to start flashing (at least on Windows 10), so I would recommend using Window.show instead. This seems to work just the same, but does not make the taskbar icon flash.

Full code:

Window.bind(on_cursor_enter=lambda *__: Window.show())
Related