Inconsistency detecting keyboard events with MouseKeyHook in Gamma

In their example code they call Hook.GlobalEvents only once and they also clean the hook up with a call to Dispose. Just played shortly with an example as posted by @bjoern here and after some F8/F5 the mouse started to stutter and the whole program crashed after a few seconds later. So cleaning that hook up seems to be mandatory. Installing it only once is probably also a good idea.

Attached you’ll find @bjoern’s patch with a proper lifetime management of that global hook by making use of two nodes in the Resources category. They will take care that only one hook exists per application and that hook also gets uninstalled when the application shuts down. The NewPooled (PerApp NoKey) region sets up a resource provider per application - when asked for its resource (the hook in this case) by multiple sinks it will hand out the same one to all of them. The Using (Process) node fetches and stores a handle to that resource - it will release that handle when the process node itself dies (for example through F8 or by deleting the node), and once all those sinks released their handles, the original resource which was handed by the resource provider will be disposed of - the hook gets uninstalled.

Here is a screenshot of that logic wrapped in an easy to use process called GlobalEvents
grafik

MKH(1).vl (73.8 KB)

Running this patch I had no more crashes. Maybe it helps you as well in your going fullscreen scenario.

4 Likes