I’m attempting to suppress some Windows keyboard shortcuts (e.g. ALT + TAB, LWIN/RWIN, ALT + F4) so my application can handle them elsehow (simulating keypresses on an external machine).
According to other SO questions and answers this is supposed to work:
this.PreviewKeyDown += (s, e) => {
if (e.Key == Key.LWin || e.Key == Key.RWin)
e.Handled = true;
};
Problem is, it doesn’t work. Whenever I hit LWIN/RWIN, the Start menu still pops up which I want to suppress so my application alone can use it. In the above snippet, this refers to a WPF Window which was being focussed while testing this. (It should obviously only suppress the action once Window has focus.)
Any way to achieve what I’d like to achieve?
Thanks,
~Tgys
You can Hook all the Keyboard and even Mouse events to detect the source of input. In other words, if you use the Global Hook as mentioned in the link below, you can capture system events and either process them like normal events or suppress them.
You should have a look at this CodeProject article, Processing Global Mouse and Keyboard Hooks in C#
MSDN Reference:
C# Code:
Other Good References: