struct cxpr cxacosh (struct cxpr z) { struct cxpr w; struct xpr ls, rs; w = cxsqrt (cxsub (cxsqr (z), cxOne)); ls = cxabs (cxsum (z, w)); rs = xmul (xVSV, cxabs (z)); if (xprcmp (&ls, &rs) < 0) return cxneg (cxlog (cxsub (z, w))); else return cxlog (cxsum (z, w)); }
int main(int argc, const char** argv) { MSG msg; init_debug(); status = parse_arguments(argc, argv); if (status) { if (status == 2) usage(); else fprintf(stderr, "Issue %s --help for usage.\n", *argv); return RC_INVALID_ARGUMENTS; } cxlog("Entering message loop. action=%d\n", g_action); if (g_timeout>0) SetTimer(NULL, 0, g_timeout, TimeoutProc); timer_id=SetTimer(NULL, 0, 100, FindWindowProc); status=RC_RUNNING; while (status==RC_RUNNING && GetMessage(&msg, NULL, 0, 0)!=0) { TranslateMessage(&msg); DispatchMessage(&msg); } return status; }
struct cxpr cxasinh (struct cxpr z) { struct cxpr w; struct xpr ls, rs; /* In this way, cxasinh() works fine also with real numbers */ /* very near to -oo. */ w = cxsqrt (cxsum (cxOne, cxsqr (z))); ls = cxabs (cxsum (z, w)); rs = xmul (xVSV, cxabs (z)); if (xprcmp (&ls, &rs) < 0) return cxneg (cxlog (cxsub (w, z))); else return cxlog (cxsum (z, w)); }
static void CALLBACK FindWindowProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) { HWND window = find_window(); if (!window) return; cxlog("Found the window\n"); if (g_delay) { cxlog("Waiting for a bit\n"); KillTimer(NULL, timer_id); timer_id=SetTimer(NULL, 0, g_delay, DelayProc); do_click(window, 0,0); } else { DelayProc(NULL, 0, 0, 0); } }
static void CALLBACK ClickProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) { HWND window = find_window(); if (!window) { if (g_untildeath) { /* FIXME: The window / control might just be disabled and if * that's the case we should not exit yet. But I don't expect * --untildeath to be used at all anyway so fixing this can * wait until it becomes necessary. */ status=RC_SUCCESS; } else cxlog("The window has disappeared!\n"); return; } switch (g_action) { case ACTION_FIND: /* Nothing to do */ break; case ACTION_LCLICK: cxlog("Sending left click\n"); do_click(window, MOUSEEVENTF_LEFTDOWN, MOUSEEVENTF_LEFTUP); break; case ACTION_MCLICK: cxlog("Sending middle click\n"); do_click(window, MOUSEEVENTF_MIDDLEDOWN, MOUSEEVENTF_MIDDLEUP); break; case ACTION_RCLICK: cxlog("Sending right click\n"); do_click(window, MOUSEEVENTF_RIGHTDOWN, MOUSEEVENTF_RIGHTUP); default: fprintf(stderr, "error: unknown action %d\n", g_action); break; } if (!g_repeat) status=RC_SUCCESS; }
static void CALLBACK DelayProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) { KillTimer(NULL, timer_id); timer_id=0; if (g_repeat) { cxlog("Setting up a timer for --repeat\n"); timer_id=SetTimer(NULL, 0, g_repeat, ClickProc); } ClickProc(NULL, 0, 0, 0); }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { HINSTANCE hDll; action_t* action; init_debug(); /* Our scripts expect Unix-style line ends */ _setmode(1,_O_BINARY); _setmode(2,_O_BINARY); if (strstr(lpCmdLine,"--help")) { fprintf(stderr,"%s - Utility to print coordinates, component, window title, component class and window class name of a click\n", APP_NAME); fprintf(stderr,"----------------------------------------------\n"); fprintf(stderr,"Usage: %s\n",APP_NAME); fprintf(stderr,"The options are as follows:\n"); fprintf(stderr,"After starting you can\n"); fprintf(stderr,"select where to click. If we properly track the click, it will be reported\n"); fprintf(stderr,"in the following format:\n"); fprintf(stderr," button-name x y component_name window_name component_class_name window_class_name\n"); fprintf(stderr,"Note that x and y can be negative; this typically happens if you click within the\n"); fprintf(stderr,"window manager decorations of a given window.\n"); fprintf(stderr,"On success, %s returns 0, non zero on some failure\n",APP_NAME); exit(0); }; /* Load the hook library */ hDll = load_hook_dll(); if (!hDll) { fprintf(stderr, "Error: Unable to load 'hook.dll'\n"); printf("failed\n"); return 1; } pInstallHooks=(void*)GetProcAddress(hDll, "InstallHooks"); pRemoveHooks=(void*)GetProcAddress(hDll, "RemoveHooks"); pGetAction=(void*)GetProcAddress(hDll, "GetAction"); pFreeAction=(void*)GetProcAddress(hDll, "FreeAction"); if (!pInstallHooks || !pRemoveHooks || !pGetAction) { fprintf(stderr, "Error: Unable to get the hook.dll functions (%ld)\n", GetLastError()); printf("failed\n"); return 1; } if (!pInstallHooks(hDll)) { fprintf(stderr, "Error: Unable to install the hooks (%ld)\n", GetLastError()); printf("failed\n"); return 1; } fprintf(stderr, "Ready for capture...\n"); action=pGetAction(); if (!action) { fprintf(stderr, "Error: GetAction() failed\n"); printf("failed\n"); return 1; } switch (action->action) { case ACTION_FAILED: printf("failed\n"); break; case ACTION_NONE: printf("none\n"); break; case ACTION_FIND: printf("find\n"); break; case ACTION_BUTTON1: case ACTION_BUTTON2: case ACTION_BUTTON3: printf("button%d %ld %ld\n", action->action-ACTION_BUTTON1+1, action->x, action->y); break; default: fprintf(stderr, "Error: Unknown action %d\n",action->action); printf("%d\n", action->action); break; } printf("%s\n", action->window_class); printf("%s\n", action->window_title); printf("%ld\n", action->control_id); printf("%s\n", action->control_class); printf("%s\n", cleanup(action->control_caption)); cxlog("\n%s: action=%d x=%ld y=%ld\n", __FILE__, action->action, action->x, action->y); cxlog("window_class='%s'\n", action->window_class); cxlog("window_title='%s'\n", action->window_title); cxlog("control_id=%ld\n", action->control_id); cxlog("control_class='%s'\n", action->control_class); cxlog("control_caption='%s'\n", action->control_caption); pFreeAction(action); pRemoveHooks(); return 0; }