Receive events without focus

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Receive events without focus

Thomas Güttler-2
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

  Thanks,
    Thomas

--
Thomas Guettler http://www.thomas-guettler.de/
_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/
Reply | Threaded
Open this post in threaded view
|

Re: Receive events without focus

Robert Schroll
On 05/31/2013 04:44 AM, Thomas Guettler wrote:
> I write a native GUI with gtk, which needs to receive keyboard events
> although the window does not have the focus.

You might want to take a look at programs that show keypresses for use
in screencasts and demonstrations, since these have to notice keypresses
without having focus.  A few years back, I toyed with key-mon
(http://code.google.com/p/key-mon/), a pygtk program that does this on
linux.  While googling for this, I stumbled across pykeyview
(https://github.com/mattharrison/pykeyview).  I haven't tried this, but
it looks a lot more basic, which might make it easier to figure out.

It looks like both get the keypress events from X, so you'd presumably
need another solution for windows.

Hope that helps,
Robert

_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/
Reply | Threaded
Open this post in threaded view
|

Re: Receive events without focus

Tim Evans-2
In reply to this post by Thomas Güttler-2
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   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/
Reply | Threaded
Open this post in threaded view
|

Re: Receive events without focus

Thomas Güttler-2
Am 04.06.2013 00:14, schrieb Tim Evans:
...

>
> 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.

I think these key words help me to find a solution.

Thank you,
   Thomas Güttler

--
Thomas Guettler http://www.thomas-guettler.de/
_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/