2

I wrote a program which render overlay in game, showing some additional info. I can detect keyboard and some of mouse keypresses by using GetKeyState, however there is no Virtual Key Code for scroll up and down which I would like to use as well.

I know that scroll is handled more in a way of an event, rather than keypress, but that doesn't really help. So is there any solutions for my problem?

Things that came to my mind:

  1. Detect scroll events by some function?
  2. Somehow get Windows Messages sent to game in my program (thats called Hooking IIRC)

I'm using Visual Studio 2013 Express [C++]

Jeremy Friesner
  • 70,199
  • 15
  • 131
  • 234
user3213103
  • 133
  • 3
  • 14

4 Answers4

1

Check SetWindowsHookEx: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644990(v=vs.85).aspx and WH_MOUSE in particular.

c-smile
  • 26,734
  • 7
  • 59
  • 86
1

I solved the issue by using following code.

LRESULT CALLBACK mouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
    using namespace MouseLog;
    MSLLHOOKSTRUCT * pMouseStruct = (MSLLHOOKSTRUCT *)lParam;

    if (pMouseStruct != NULL)
    {
        if (wParam == WM_MOUSEWHEEL)
        {
            if (HIWORD(pMouseStruct->mouseData) == 120) MScrollUp = 1;
            else MScrollDown = 1;
        }
        if (wParam == WM_MBUTTONDOWN)
            MScrollBtn = 1;

        //printf("Mouse position X = %d  Mouse Position Y = %d\n", pMouseStruct->pt.x, pMouseStruct->pt.y);
    }
    return CallNextHookEx(hMouseHook, nCode, wParam, lParam);
}

DWORD WINAPI MouseLogger(LPVOID lpParm)
{
    HINSTANCE hInstance = GetModuleHandle(NULL);
    hMouseHook = SetWindowsHookEx(WH_MOUSE_LL, mouseProc, hInstance, NULL);

    MSG message;
    while (GetMessage(&message, NULL, 0, 0)) {
        TranslateMessage(&message);
        DispatchMessage(&message);
    }
    UnhookWindowsHookEx(hMouseHook);
    return 0;
}

For starting MouseLogger use CreateThread().

user3213103
  • 133
  • 3
  • 14
0

I understand that theres no keystate for mouse scrolling but theres something else like WM_MOUSEWHEEL

If this answers your question you might want to check out this

http://msdn.microsoft.com/en-us/library/windows/desktop/ms645617(v=vs.85).aspx

otherwise if this dont help you i would be glad to help you if this dosent help

BrainDamage
  • 34
  • 1
  • 9
0

You can use the legacy gaming API, DirectInput. I know that definitely works when the window is in the background when you use the DISCL_BACKGROUND flag.

selbie
  • 100,020
  • 15
  • 103
  • 173