alternative to mickey.z

Posted By: Reconnoiter

alternative to mickey.z - 03/04/17 12:01

Hello,

Since mickey.z is broken with touchpad and touchscreen zooming (as in it continues to stay on the value), I would like to use an alternative. I found this https://msdn.microsoft.com/en-us/library/windows/desktop/ms645617(v=vs.85).aspx on msdn, but cannot get it working. Does anyone have a snippet for this or something similar?
If this is not possible, than I have thought of maybe resetting mickey.z to 0 overtime, but it seems to be readonly.
Posted By: Ch40zzC0d3r

Re: alternative to mickey.z - 03/04/17 12:30

SetWindowsHookEx and checking the WM_MOUSEWHEEL works perfectly fine laugh
Posted By: Reconnoiter

Re: alternative to mickey.z - 03/04/17 14:32

But how do you get the compiler to recognize e.g. HHOOK (HHOOK _hook;)? I get errors even while I included stuff like #include <Windows.h> . And stuff like Winuser.h cannot be found.
(I am using this currently as example: https://www.unknowncheats.me/forum/c-and-c/83707-setwindowshookex-example.html)
Posted By: Ch40zzC0d3r

Re: alternative to mickey.z - 03/04/17 15:13

Code:
typedef void *HHOOK;

typedef struct tagKBDLLHOOKSTRUCT {
    DWORD   vkCode;
    DWORD   scanCode;
    DWORD   flags;
    DWORD   time;
    ULONG_PTR dwExtraInfo;
} KBDLLHOOKSTRUCT, FAR *LPKBDLLHOOKSTRUCT, *PKBDLLHOOKSTRUCT;



All you need is to open WinUser.h in Visual Studio and rip the structs if you cannot include them.
Acknex has its own Windows.h, alot of windows standard includes are missing.
Posted By: Reconnoiter

Re: alternative to mickey.z - 03/04/17 16:12

Ty, how to fix this line?:
kbdStruct = *((KBDLLHOOKSTRUCT*)lParam);

I get a wrong type error with it.
Posted By: Ch40zzC0d3r

Re: alternative to mickey.z - 03/04/17 17:59

I dont understand why he derefs it at all, you can simply use a pointer directly like this:
Code:
KBDLLHOOKSTRUCT *pKbdStruct = (KBDLLHOOKSTRUCT*)lParam;
pKbdStruct->...

Posted By: Reconnoiter

Re: alternative to mickey.z - 03/05/17 12:51

Okay thanks seems to work I get the message boxes etc.
For others:

Code:
#define WH_KEYBOARD_LL     13
#define WH_MOUSE_LL        14
#define MB_ICONERROR			0x00000010L

typedef void *HHOOK;

typedef struct tagKBDLLHOOKSTRUCT {
    DWORD   vkCode;
    DWORD   scanCode;
    DWORD   flags;
    DWORD   time;
    long dwExtraInfo;
//    ULONG_PTR dwExtraInfo;
} KBDLLHOOKSTRUCT; //, FAR *LPKBDLLHOOKSTRUCT, *PKBDLLHOOKSTRUCT;

KBDLLHOOKSTRUCT *pKbdStruct;

// Callback function (called when a key is pressed) 
LRESULT __stdcall HookCallback(int nCode, WPARAM wParam, LPARAM lParam) {
    if (nCode >= 0) {
        // the action is valid: HC_ACTION.
        if (wParam == WM_KEYDOWN) {
            // lParam is the pointer to the struct containing the data needed, so cast and assign it to kdbStruct
            pKbdStruct = (KBDLLHOOKSTRUCT*)lParam;
//            kbdStruct = *((KBDLLHOOKSTRUCT*)lParam);
            // a key (non-system) is pressed.
            if (pKbdStruct.vkCode == VK_F1) {
                // F1 is pressed!
                MessageBox(NULL, "F1 is pressed!", "key pressed", MB_ICONINFORMATION);
            }
        }
    }

    // call the next hook in the hook chain. This is nessecary or your hook chain will break and the hook stops
    return CallNextHookEx(_hook, nCode, wParam, lParam);
}

void SetHook() {
    // Set the hook and set it to use the callback function above
    // WH_KEYBOARD_LL means it will set a low level keyboard hook. More information about it at MSDN.
    // The last 2 parameters are NULL, 0 because the callback function is in the same thread and window as the
    // function that sets and releases the hook. If you create a hack you will not need the callback function 
    // in another place then your own code file anyway. Read more about it at MSDN.
    if (!(_hook = SetWindowsHookEx(WH_KEYBOARD_LL, HookCallback, NULL, 0))) { 
        MessageBox(NULL, "Failed to install hook!", "Error", MB_ICONERROR);
    }

}

void ReleaseHook() {
    UnhookWindowsHookEx(_hook);
}


void init_startup () {
    // Set the hook
    SetHook();	
    on_close = ReleaseHook; 
    on_exit = ReleaseHook; 
}

© 2024 lite-C Forums