Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there a native .NET method or equivalent to user32.dll's GetKeyboardState?
    primarykey
    data
    text
    <p><strong>ANSWER:</strong> There isn't a natively managed equivalent for this method. However, a good example managed code API can be found over at <a href="http://www.pinvoke.net/default.aspx/user32.getkeyboardstate" rel="nofollow noreferrer">pinvoke.net</a>.</p> <p>Hi all</p> <p>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.</p> <p>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.</p> <p>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.</p> <p>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.</p> <p>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.</p> <p>Is there a native .NET method or equivalent to user32.dll's GetKeyboardState?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload