hello, I'm relatively new to c++ so please bare with me. I'm trying to write a program where the mouse will start moving when a key is pressed then stop when the key is released. I thought I had it but the mouse keeps going after the key is released. I think it's because my mmx function calls itself and the kbHookProc function can't listens for the release but I don't know how to get around this. Can somebody help? I know about mouse keys but I'm working with someone with a disability and have some odd parameters. Here is my code
Code:#define _WIN32_WINNT 0x0500 #include<windows.h> using namespace std; int xg=0,nmy,nmx,x,y; POINT p; int mmx() { GetCursorPos(&p); x=p.x+1; y=p.y; SetCursorPos(x, y); Sleep(300); if (xg==1) mmx(); return 0; } LRESULT CALLBACK kbHookProc(int nCode, WPARAM wParam, LPARAM lParam) { if(lParam>0) { xg=1; mmx(); } else { xg=0; } } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { // Set mouse hook HHOOK mouseHook = SetWindowsHookEx( WH_KEYBOARD, /* Type of hook */ kbHookProc, /* Hook process */ hInstance, /* Instance */ 0); // Wait for user to exit MessageBox(NULL, "Press OK to close.", "", MB_OK); return 0; }



LinkBack URL
About LinkBacks



