1. 程式人生 > >關閉或開啟筆記本觸控滑鼠功能(TouchPad)

關閉或開啟筆記本觸控滑鼠功能(TouchPad)

只能使用在Synaptics Touchpad且要安裝Synaptics軟體。
#include <stdio.h>
#include "SynKit.h"

int main(
  int argc, 
  char* argv[])
{
  ISynAPI 
    *pAPI = 0;

  if ( CoInitialize(0) ||
    CoCreateInstance(_uuidof(SynAPI), 0, 
    CLSCTX_INPROC_SERVER, _uuidof(ISynAPI), (void **) &pAPI) ||
    pAPI->Initialize() )
  {
    printf("ERROR: Could not obtain a Synaptics API object.\n");
    return 1;
  }

  ISynDevice 
    *pDev = NULL;

  long 
    lDev = -1;

  // serach current device.
  if ( pAPI->FindDevice(SE_ConnectionAny, SE_DeviceTouchPad, &lDev) ||
    pAPI->CreateDevice(lDev, &pDev) )
  {
    printf("ERROR: Unable to find a Synaptics TouchPad.\n");
    goto Quit;
  }

  long 
    value = -1;

  // get current state of the touchpad.
  if ( pDev->GetProperty(SP_DisableState, &value) != S_OK )
  {
    // is query mode. will report an error.
    if ( !argc )
    {
      printf("ERROR: get state fail.\n");
      goto Quit;
    }

    // reset state value.
    value = -1;
  }

  // set state mode.
  if ( argc > 0 )
  {
    // turn off.
    if ( !strcmpi(argv[1], "off") )
    {
      // if the current state is not off.
      if ( value != 1 }
      {
        // 
        if ( pDev->SetProperty(SP_DisableState, 1) != S_OK )
        {
          printf("ERROR: Turn off fail.\n\n");
          goto Quit;
        }
      }

      printf("Turn off OK.\n");
    }
    else if ( !strcmpi(argv[1], "on") )
    {
      if ( value != 0 }
      {
        if ( pDev->SetProperty(SP_DisableState, 0) != S_OK )
        {
          printf("ERROR: Turn on fail.\n\n");
          goto Quit;
        }
      }

      printf("Turn on OK.\n");
    }
    else
    {
      printf("ERROR: Invalid parameter.\n");
      goto Quit;
    }

  }
  else
  {
    if ( value )
      printf("Device Off\n");
    else
      printf("Device On\n");
  }

Quit:
  if ( pDev ) pDev->Release();
  if ( pAPI ) pAPI->Release();

  return 0;
}