ANSWER: There isn't a natively managed equivalent for this method. However, a good example managed code API can be found over at pinvoke.net.
Hi all
I have an application that accepts a flag for 'trace mode'. Trace mode turns on a form containing a text box. The text box displays output via a custom TraceListener object. If there is a -t present on the command-line, the trace window will be opened from within its own low-priority thread. It's handy for consultants that are trying to diagnose the application when something goes wrong.
A few consultants have requested that pressing some obscure key combination during startup should turn on trace mode so they don't have to go to the command line to activate it every time. It's a reasonable request.
I don't want to give them a button or menu item for this because a lot of the critical information that the consultants will care about is displayed to Trace at startup before the main form is created as the various components are instantiated and initialized.
I thought it should have been simple enough to detect the current keyboard state in .NET - but it seems that everywhere I look, the advice is to use [DllImport("user32.dll", EntryPoint = "GetKeyboardState", SetLastError = true)] as the method to detect what's going on.
That's all well and good - I'm comfortable with that. However, as a general rule of thumb I try to make sure I use native .NET managed code for Windows functions before I go trying to roll my own.
Is there a native .NET method or equivalent to user32.dll's GetKeyboardState?