低级键盘钩子到普通DLL钩子的参数转换


LRESULT CALLBACK KeyboardHookAll(int nCode, WPARAM wParam, LPARAM lParam)
{
 if(nCode == HC_ACTION )
 {
   long ret=2;
  HWND hwnd1 = GetFocus();
  if(hwnd1 == NULL)
  {
   long   id=GetCurrentThreadId();  
   if(idCurThread != 0)
    AttachThreadInput(id, idCurThread, FALSE);
   HWND   hwnd=GetForegroundWindow();  
   idCurThread=GetWindowThreadProcessId(hwnd,0);  
   AttachThreadInput(id,idCurThread,TRUE);           //连接线程  
   hwnd1=GetFocus();  
  }
  if(hwnd1 != NULL)
  {
   KBDLLHOOKSTRUCT *pkbdllHook   = (KBDLLHOOKSTRUCT*)lParam;
   MYKey.hFocus=hwnd1;
   MYKey.wParam = pkbdllHook->vkCode;

   if(MYKey.wParam > 0x9f && MYKey.wParam < 0xa6)
    MYKey.wParam = MYKey.wParam / 2 - 0x40;

   MYKey.lParam =0;
   MYKey.lParam |= (pkbdllHook->scanCode << 16);
   MYKey.lParam |= 0x01;

   if(pkbdllHook->flags & 0x01)
    MYKey.lParam |= 0x1000000;
   if(pkbdllHook->flags & 0x20)
    MYKey.lParam |= 0x20000000;
   if(pkbdllHook->flags & 0x80)
    MYKey.lParam |= 0x80000000;

   GetCaretPos(&MYKey.CaretPos);
   ClientToScreen(MYKey.hFocus,&MYKey.CaretPos);
   pKey = &MYKey;
 //  memset(pKey->cKeys, 0, 256);
 //  GetKeyboardState( (LPBYTE)(pKey->cKeys));
  // ret = SendMessage(hMainWnd, WM_CHAR, 0, 0);
   switch (wParam)
   {
   case WM_KEYDOWN:
   case WM_SYSKEYDOWN:
    switch (pkbdllHook->vkCode)
    {
    case VK_LWIN:
     {
      pKey->cKeys[VK_LWIN] = 0x80;
      break;
     }
    case VK_RWIN:
     {
      pKey->cKeys[VK_RWIN] = 0x80;
      break;
     }
    case VK_LSHIFT:
    case VK_RSHIFT:
    case VK_SHIFT:
     {
      pKey->cKeys[VK_SHIFT] = 0x80;
      break;
     }
    case VK_ESCAPE:
     {
      pKey->cKeys[VK_ESCAPE] = 0x80;
      break;
     }
    case VK_CONTROL:
    case VK_LCONTROL:
    case VK_RCONTROL:
     {
      pKey->cKeys[VK_CONTROL] = 0x80;
      break;     
     }
    case VK_DELETE:
     {
      pKey->cKeys[VK_DELETE] = 0x80;
      break;     
     }
    case VK_NEXT:
     {
      pKey->cKeys[VK_NEXT] = 0x80;
      break;     
     }
    case VK_PRIOR:
     {
      pKey->cKeys[VK_PRIOR] = 0x80;
      break;     
     }
    case VK_HOME:
     {
      pKey->cKeys[VK_HOME] = 0x80;
      break;     
     }
    case VK_END:
     {
      pKey->cKeys[VK_END] = 0x80;
      break;     
     }
 
    case VK_LEFT:
     {
      pKey->cKeys[VK_LEFT] = 0x80;
      break;     
     } 
    case VK_RIGHT:
     {
      pKey->cKeys[VK_RIGHT] = 0x80;
      break;     
     }
    }
    break;
   case WM_KEYUP:
   case WM_SYSKEYUP:
    switch (pkbdllHook->vkCode)
    {
    case VK_LWIN:
     {
      pKey->cKeys[VK_LWIN] = 0;
      break;
     }
    case VK_RWIN:
     {
      pKey->cKeys[VK_RWIN] = 0;
      break;
     }
    case VK_LSHIFT:
    case VK_RSHIFT:
    case VK_SHIFT:
     {
      pKey->cKeys[VK_SHIFT] = 0;
      break;
     }
    case VK_CONTROL:
    case VK_LCONTROL:
    case VK_RCONTROL:
     {
      pKey->cKeys[VK_CONTROL] = 0;
      break;     
     }
    case VK_DELETE:
     {
      pKey->cKeys[VK_DELETE] = 0;
      break;     
     }
    case VK_NEXT:
     {
      pKey->cKeys[VK_NEXT] = 0;
      break;     
     }
    case VK_PRIOR:
     {
      pKey->cKeys[VK_PRIOR] = 0;
      break;     
     }
    case VK_HOME:
     {
      pKey->cKeys[VK_HOME] = 0;
      break;     
     }
    case VK_END:
     {
      pKey->cKeys[VK_END] = 0;
      break;     
     }
 
    case VK_LEFT:
     {
      pKey->cKeys[VK_LEFT] = 0;
      break;     
     }
    case VK_RIGHT:
     {
      pKey->cKeys[VK_RIGHT] = 0;
      break;     
     }
    }
    break;
   }
   //SHORT b = GetKeyState(VK_CAPITAL);
   //SHORT c = GetAsyncKeyState(VK_CAPITAL);
   if( GetKeyState(VK_CAPITAL) & 1)
    pKey->cKeys[VK_CAPITAL] =  1;
   else
    pKey->cKeys[VK_CAPITAL] =  0;
 /*  if((pKey->wParam == 0x56 || pKey->wParam == 0x43) && pKey->cKeys[VK_CONTROL] & 0x80)
    return CallNextHookEx(hExeHook, nCode, wParam, lParam);*/
   if(pKey->cKeys[VK_LWIN] & 0x80 || pKey->cKeys[VK_RWIN] & 0x80)
    return CallNextHookEx(hExeHook, nCode, wParam, lParam);

   ret = OnChar1(pkbdllHook->scanCode);
  }
  return ret!=2 ? ret :
   CallNextHookEx( hExeHook, nCode, wParam, lParam );
 }
 return CallNextHookEx(hExeHook, nCode, wParam, lParam);
}
 

你可能感兴趣的:(c,null,delete,dll,action,callback)