title: Win32 determining when keyboard is connected/disconnected
body: <p>I am trying to determine when my keyboard is connected or disconnected.  I have tried the following strategies:</p>
  
  <p><strong>RegisterDeviceNotification</strong></p>
  
  <p>Using RegisterDeviceNotifaction as explained on <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa363432%28v=vs.85%29.aspx" rel="nofollow noreferrer">MSDN</a> was suggested in <a href="https://stackoverflow.com/questions/9333663/how-to-determine-keyboard-disconnected-in-directinput">how to determine keyboard disconnected in DirectInput</a>.  When I tried this I get <code>DB_DEVNODES_CHANGED</code> event in the window callback which provides no other information (just <em>some unknown</em> device has changed connection state).  I tried various GUIDs for the registration: <code>4D36E96B-E325-11CE-BFC1-08002BE10318</code> (several websites said this is the class guid for keyboards) and the guidInstance retrieved from <code>IDirectInput8::EnumDevices(DI8DEVCLASS_KEYBOARD, ..., DIEDFL_ATTACHEDONLY)</code>.  But I still only get the <code>DB_DEVNODES_CHANGED</code> event.</p>
  
  <p><strong>IDirectInput8::EnumDevices</strong></p>
  
  <p>Each call to <code>IDirectInput8::EnumDevices(DI8DEVCLASS_KEYBOARD, ..., DIEDFL_ATTACHEDONLY)</code> should only enumerate the devices that are attached.  However, when I disconnect my keyboard, it still gets enumerated by <code>EnumDevices</code>.  When I do the same for my game controller (with the type <code>DI8DEVCLASS_GAMECTRL</code>) the controller is only enumerated when it is attached, allowing me to determine its connection state.</p>
  
  <p><strong>Other Functions</strong></p>
  
  <p>I have tried:</p>
  
  <ol>
  <li><code>IDirectInput8::GetDeviceStatus</code></li>
  <li><code>IDirectInputDevice8::GetCapabilities</code></li>
  <li><code>IDirectInputDevice8::GetDeviceInfo</code></li>
  <li><code>IDirectInputDevice8::GetDeviceState</code></li>
  <li><code>IDirectInputDevice8::Poll</code></li>
  </ol>
  
  <p>All functions succeed and provide no insight into if the keyboard is connected.</p>
  
  <p>I have also looked through MSDN's <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms645530%28v=vs.85%29.aspx" rel="nofollow noreferrer">keyboard section</a>, to no avail.</p>
  
  <p><strong>Questions</strong></p>
  
  <ol>
  <li>Can anyone who has done this successfully confirm I'm taking the right approach?</li>
  <li>Is there another function or API I am overlooking?</li>
  <li>Any websites that give an example (I've googled unsuccessfully)?</li>
  <li>Why does <code>EnumDevices</code> work correctly for my controller but not my keyboard?  And how do I make it work for my keyboard?</li>
  </ol>