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

"e.Handled = true" not supress inputs in KeyPress event #99

Open EEmmanuelLG opened 6 years ago

EEmmanuelLG commented 6 years ago

I have this code in the event:

private void HookManager_KeyPress(object sender, KeyPressEventArgs e)
        {
            Log(string.Format("KeyPress \t\t {0}\n", e.KeyChar));
            e.Handled = true;
        }

The KeyChar is displaying in the form but is not handled in other applications. If I add the event KeyDown and do the same it works, but in KeyPress doesn't works.

thavious commented 5 years ago

` protected override bool Callback(CallbackData data) { var eDownUp = GetDownUpEventArgs(data);

        InvokeKeyDown(eDownUp);

        if (KeyPress != null)
        {
            var pressEventArgs = GetPressEventArgs(data);
            foreach (var pressEventArg in pressEventArgs)
            {
                InvokeKeyPress(pressEventArg);
                eDownUp.Handled = eDownUp.Handled || pressEventArg.Handled;
            }
        }

        InvokeKeyUp(eDownUp);

        return !eDownUp.Handled;
    }`

See the line added after InvokeKeyPress: eDownUp.Handled = eDownUp.Handled || pressEventArg.Handled;