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

How to recognize key combinations? #81

Closed asim1337 closed 6 years ago

asim1337 commented 7 years ago

I can't figure out the most obvious function.. How can i recognize key combinations? I tried: private void M_GlobalHook_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)0x41 && e.KeyChar == (char)0xA2) { MessageBox.Show("Left Ctrl + A pressed!"); } }

caschw commented 7 years ago

I'm doing the following in my code to detect shift + caps lock and ctrl+caps lock.

public MyClass()
{
    KeyboardListener = new KeyboardHookListener(new GlobalHooker()) {Enabled = true};
    KeyboardListener.KeyDown += KeyboardListener_KeyDown;
}

private void KeyboardListener_KeyDown(object sender, KeyEventArgs e)
{
    // Holding down Shift and CapsLock, not already suspending toggle
    if (e.Shift && e.KeyValue == 20){...}
    // Holding down Control and Capslock, suspending of toggle active
    else if (e.Control && e.KeyValue == 20){...}
}
gmamaladze commented 6 years ago

See new feature Detecting Key Combinations and Sequences