title: Create Application: On-Off Mouse-Keyboard By Microphone Sound Level
body: <p>I need to make in practice a application running in WIN7.
  This application must read continuously the sound(noise) received from the microphone and, if the level of the sound(noise) is higher that a value, to activate to display a Jpeg image on the screen and at the same time to deactivate the mouse and the keyboard. To have a adjusted delay and after the delay time to reactivate the mouse and the keyboard.
  This application must start at StartUp of PC.
  I need to use this application in a computer class room at every PC with WIN7.
  This can be a batch file or a C++ or everything else.
  Can somebody help me ???</p>
  
  <p>I found this related to read microphone input level:</p>
  
  <p>static float peak = 5;</p>
  
  <p>while(1)</p>
  
  <p>{
   HRESULT hr;</p>
  
  <pre><code>IMMDeviceEnumerator *pEnumerator = NULL;
  IMMDevice *pDevice = NULL;
  IAudioMeterInformation *pMeterInfo = NULL;
  
  CoInitialize(NULL);
  
  // Get enumerator for audio endpoint devices.
  hr = CoCreateInstance(__uuidof(MMDeviceEnumerator),
                        NULL, CLSCTX_INPROC_SERVER,
                        __uuidof(IMMDeviceEnumerator),
                        (void**)&amp;pEnumerator);
  EXIT_ON_ERROR(hr)
  
  // Get peak meter for default audio-capturing device.
  hr = pEnumerator-&gt;GetDefaultAudioEndpoint(eCapture, eConsole, &amp;pDevice);
  EXIT_ON_ERROR(hr)
  
  hr = pDevice-&gt;Activate(__uuidof(IAudioMeterInformation),
                         CLSCTX_ALL, NULL, (void**)&amp;pMeterInfo);
  EXIT_ON_ERROR(hr)
  </code></pre>
  
  <p>hr = pMeterInfo->GetPeakValue(&amp;peak);</p>
  
  <p>printf("\rCurrent volume as a scalar is: %f", peak);</p>
  
  <p>Sleep(500); // update every half-second</p>
  
  <p>Exit:</p>
  
  <pre><code>if (FAILED(hr))
  
  {
      MessageBox(NULL, TEXT("This program requires Win7."),
                 TEXT("Error termination"), MB_OK);
  }
  SAFE_RELEASE(pEnumerator)
  SAFE_RELEASE(pDevice)
  SAFE_RELEASE(pMeterInfo)
  CoUninitialize();
  </code></pre>
  
  <p>I found this related to On/Off input for keyboard and mouse:</p>
  
  <p>class MyClass</p>
  
  <p>{
    [DllImport("user32.dll")]</p>
  
  <p>private static extern bool BlockInput(bool fBlockIt);</p>
  
  <p>private static void MyMethod()</p>
  
  <p>{</p>
  
  <pre><code>BlockInput(true);
  
  Run(@DesktopDir &amp; "\autoit\" &amp; "mu.exe", "")
  
  Thread.Sleep(60000);
  
  BlockInput(false);
  </code></pre>
  
  <p>}</p>
  
  <p>}</p>
  
  <p>I dont cnow how to maried them for a final executable program running at StartUp</p>