Keyboard hook get key combination (WPF)

前端 未结 3 474
别那么骄傲
别那么骄傲 2021-01-26 15:16

I tried using this post here: Using global keyboard hook (WH_KEYBOARD_LL) in WPF / C# And i have this sucessfully working.

But there is something i cant get my finger be

3条回答
  •  温柔的废话
    2021-01-26 15:52

    Store the value of the key that is pressed and the next time your method is called check if this stored value and the actual value are your key combination.

        var lastKey;
    void KListener_KeyDown(object sender, RawKeyEventArgs args)
            {
    
                Console.WriteLine(args.Key.ToString());
                if (lastKey == Key.LeftCtrl && args.Key == Key.C)
                {
                    MessageBox.Show(args.Key.ToString());
                }
               lastKey = args.Key;
            }
    

提交回复
热议问题