gmamaladze / globalmousekeyhook

This library allows you to tap keyboard and mouse, detect and record their activity even when an application is inactive and runs in background.
MIT License
1.05k stars 257 forks source link

OnCombination raises other combination(s) containing - Bug or feature? #126

Open guzelonur opened 4 years ago

guzelonur commented 4 years ago

First of all, thanks for creating such a great project. I'm using latest version and what I have just found; Combinations registered by OnCombination from "Combination.FromString" have such strange behaviour, resulting in raising other combinations if the combination defined in code is "contained" in user's input combination.

Consider that simple code: (Currently working on VB.NET platform and it works fine)

        Imports Gma.System.MouseKeyHook

        Dim hook_object As Gma.System.MouseKeyHook.IKeyboardEvents = Hook.GlobalEvents()
        Dim assignment = New Dictionary(Of Combination, Action)
        Dim keyCombination As Combination
        Dim ProcessStart As Action = AddressOf DoJob
        keyCombination = Combination.FromString("Shift+K")
        assignment.Add(keyCombination, ProcessStart)
        hook_object.OnCombination(assignment)

       Private Sub DoJob()
           MsgBox("Raised!")
        End Sub

In the example above, when we assign "Shift+K" to hook_object via "OnCombination" method passing it as string, any key combination "containing" Shift+K is also raised such as when you press "Control+Shift+K" or "Control+Alt+Shift+K". It doesn't matter. If user has pressed such combination which includes the combination defined in code in that method, it is also raised!

Another example; if I register "Control+M" in my code, but when user presses "Control+Alt+M" or "Control+Shift+M" at runtime, the event is also raised again!

Isn't it a bug, or an expected behaviour something I'm missing? If I had registered "Control+M", the user wouldn't be able to raise event by pressing any other combination containing "Control+M" like "Control+R+M" or "Control+Alt+M" and similar within the same application session. That is the point. Also, it doesn't have to be modifier key, for example if I register "B+C" via OnCombination() method, "B+C" raises but "A+B+C" also raises at runtime, too!

I think it is a bit inconsistent behaviour in my opinion, maybe logically, and I don't know, and I couldn't find any source addressed to this issue.

Keep up good work,

Best regards!