I want to see if the user pressed for example mouse button left + ctrl key and call an event for it.
I've tried this and it didn't work:
[DllImport("user32.dll")]
static extern short GetAsyncKeyState(int VirtualKeyPressed);
while (true)
{
if (GetAsyncKeyState(0x01)>0)
{
DoJob();
}
else
{
}
}
the problem with this code was it would capture it the first time but it wouldnt the second time (this was runing in a while loop)
I believe that you can do what you are trying to accomplish with a
Window.InputBindingand aMouseBindingattached to something likeGesture="Ctrl+LeftClick".If you take this approach, you can avoid using
user32.dlland having to handle detecting the input in the code-behind.Here is a simple example of binding to a command to an input for an entire
Window:ViewModel
ICommandimplementation, just in case you aren't familiar with this approach. If you wanted, you can also pass some sort of parameter via binding as well.