Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
it doesn't work SetwindowsHookEx(),GetAsyncKeyState() and GetCursorPos().
why?
help me.
thanks.

What I have tried:

C++
POINT ptB = { 0, 0 };
    LPPOINT xy = &ptB;   //Location variables
    ::GetCursorPos(xy);    //Gets the current mouse position        
    //If the mouse moves, (i.e. the current coordinates change to print out the coordinates) print out the coordinates.
    if ((zx != xy->x) || (zy != xy->y))
    {
        //Here you need to test the edge of your monitor[0]
        //After Test, delete this and Hide the console by ShowWindow(hWnd, 0)
        zx = xy->x;
        zy = xy->y;
        string datetime = currentDateTime();
        eventData["event"] = "mouse";
        eventData["time"] = datetime;
    }
    if ((GetAsyncKeyState(VK_LBUTTON) & 0x80) != 0 || (GetAsyncKeyState(VK_RBUTTON) & 0x80) != 0 || (GetAsyncKeyState(VK_SCROLL) & 0x80) != 0)
    {
        string datetime = currentDateTime();
        eventData["event"] = "mouse";
        eventData["time"] = datetime;
    }
Posted
Updated 14-May-22 13:36pm
v2

A service is a process that runs without a desktop therefore it is impossible for it to get mouse movement and click positions or the keys pressed.
 
Share this answer
 
v2
The calling process must have WINSTA_READATTRIBUTES access to the window station.

The input desktop must be the current desktop when you call
C++
GetCursorPos
. Call
C++
OpenInputDesktop
to determine whether the current desktop is the input desktop. If it is not, call
C++
SetThreadDesktop 
with the HDESK returned by OpenInputDesktop to switch to that desktop.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900