1

I try to do screen pixel color picker and I want to copy pixel html color if user press [CTRL]+[ALT]+[C].

But this can be pressed out of application form. So I can't use keydown event of Form.

How can I do it? Maybe some API function?

Earlgray
  • 647
  • 1
  • 8
  • 31
  • You can either trap the combination as a Hot Key Combo with the [RegisterHotKey](https://msdn.microsoft.com/en-us/library/windows/desktop/ms646309(v=vs.85).aspx) API, or via a low level keyboard hook using WH_KEYBOARD_LL. The latter is necessary if your desired key combination has already been taken by another application that also used RegisterHotKey. – Idle_Mind Jul 19 '15 at 18:07

1 Answers1

-2

You need something like this http://www.c-sharpcorner.com/UploadFile/ChrisBlake/HowToPre-FilterWindowsMessgaes11232005225819PM/HowToPre-FilterWindowsMessgaes.aspx

And here is list of codes http://wiki.winehq.org/List_Of_Windows_Messages

I have done it before with left click of mouse, but you have to see how to do it with keyboard.

Basically, you intercept every message your application gets, and filter the ones you need (by checking code value). I think you can wait for message which tells that keyboard button is pressed (any button), and then check pressed keys using Keyboard class.

if ((Keyboard.IsKeyDown(Key.LeftCtrl) ||
        Keyboard.IsKeyDown(Key.RightCtrl)) &&
        (Keyboard.IsKeyDown(Key.LeftAlt) ||
        Keyboard.IsKeyDown(Key.RightAlt)) && 
        Keyboard.IsKeyDown(Key.C))
{
      //your code
}

https://msdn.microsoft.com/en-us/library/system.windows.input.keyboard(v=vs.110).aspx

miki
  • 380
  • 6
  • 15
  • "But this can be pressed out of application form." IMessageFilter won't help here if the application isn't the foreground one... – Idle_Mind Jul 19 '15 at 18:04
  • Hm, yes you are right, if it is not foreground it won't work. – miki Jul 19 '15 at 21:59
  • I have an idea, this is more workaround if you don't find solution. You can have one thread in your application, and use it for busy waiting. It sleeps for 50 ms, checks if user has buttons pressed, then sleeps again. I took 50 ms because here http://stackoverflow.com/questions/22505698/what-is-a-typical-keypress-duration i see average lenght of keypress is around 100 ms, so if that is not working you can take smaller period, until you get acceptable solution. – miki Jul 19 '15 at 22:07