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.04k stars 257 forks source link

Is there a way to detect special keys (CTRL, ALT, WIN KEY, etc.)? #148

Closed DoubleDebug closed 3 years ago

DoubleDebug commented 3 years ago

Is there a way to detect only a special key (e.g. CONTROL), instead of detecting a combination of keys (e.g. CONTROL + A)?

I can't seem to find a way to do this in the documentation. I tried using combinations, here's the code:

var specialKeys = new Dictionary<Combination, Action>
{
    {Combination.FromString("Control"), () => Debug.WriteLine("CTRL was pressed.")},
    {Combination.TriggeredBy(Keys.Alt), () => Debug.WriteLine("ALT was pressed.")},
};

Hook.GlobalEvents().OnCombination(specialKeys);

But this doesn't work. It only works with actual combinations (e.g. "Control + U", TriggeredBy(Keys.Alt).With(Keys.U)). I also tried using sequences, but that doesn't work either and gives me a compile error, saying that it was "unable to cast object of type 'Sequence' to type 'Combination'.

Can anyone help me with this and let m know if there's a way to do this using this library? Thank you in advance.

aiyamia commented 3 years ago

See #142

DoubleDebug commented 3 years ago

@aiyamia Thanks!

anastasiosskg commented 7 months ago

Is there any example code how to detect left -> ALT CTRL SHIFT?