On 2013-05-31 20:44, Thomas Guettler wrote:
Hi,
I write a native GUI with gtk, which needs to receive keyboard events
although the window does not have the focus.
The gtk window should be minified and run in background. If the user
types a shortcut, the window should get on the foreground and get the
focus.
Up to now the shortcut does not matter. It should be easy and fast to be
entered and should not clash with a shortcut which is already in use.
The GUI should run on linux and windows.
How to implement this?
I guess this needs to be implemented in a platform specific way. If you
know the answer for one platform, let me know.
I asked the same question here:
http://stackoverflow.com/questions/16834326/receive-shortcuts-without-focus
On Windows there is the RegisterHotKey function. This is not available
via GTK, so you'd have to use the win32 APIs directly. The hard part
will be getting the WM_HOTKEY message. I think you'll need to create a
window using win32all so you can handle the message. There are plenty of
example of using RegisterHotKey on the net, you'll just need to convert
them to Python using win32all or ctypes.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646309%28v=vs.85%29.aspx
The other way to do it on Windows is to load your own DLL (written in C)
into the process of each running application. I can't remember the API
for doing that, but it did have some advantages in terms of what events
you could then override.
You might look at how AutoHotkey (http://www.autohotkey.com/) does it,
or consider just using AutoHotkey to send the right keys to your app.
--
Tim Evans
_______________________________________________
pygtk mailing list pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/