Note that there are some explanatory texts on larger screens.

plurals
  1. POImplement part of c source code
    primarykey
    data
    text
    <p>My goal is to implement a program that simply returns the current mouse position (without opening up any windows, and regardless of what is running). After searching for this, the closest and simplest implementation I could find was through <a href="https://github.com/msanders/autopy/#readme" rel="nofollow">autopy</a>, a python library for doing this sort of thing. </p> <p>The function 'get_pos()' which returns the current mouse position. See the documentation <a href="http://www.autopy.org/documentation/api-reference/mouse.html" rel="nofollow">here</a>. I simply want to implement the 'get_pos()' function on its own (because that's all I need to include from autopy for the program I am developing).</p> <p>In a github repo, I have searched through the source code of autopy and I have come to the following conclusions. Calling 'get_pos()' causes the *mouse_get_pos function to occur (see complete code <a href="https://github.com/msanders/autopy/blob/38e5ecc7cf6e3a19bd37935e577984312e0930a2/src/autopy-mouse-module.c" rel="nofollow">here</a>):</p> <pre><code>/* Syntax: get_pos() =&gt; tuple (x, y) */ /* Description: Returns a tuple `(x, y)` of the current mouse position. */ static PyObject *mouse_get_pos(PyObject *self, PyObject *args); </code></pre> <p>This function seems to call 'getMousePos':</p> <pre><code>static PyObject *mouse_get_pos(PyObject *self, PyObject *args) { MMPoint pos = getMousePos(); return Py_BuildValue("kk", pos.x, pos.y); } </code></pre> <p>Which is located in the <a href="https://github.com/msanders/autopy/blob/38e5ecc7cf6e3a19bd37935e577984312e0930a2/src/mouse.c" rel="nofollow">mouse.c</a> header file:</p> <pre><code>MMPoint getMousePos() { #if defined(IS_MACOSX) CGEventRef event = CGEventCreate(NULL); CGPoint point = CGEventGetLocation(event); CFRelease(event); return MMPointFromCGPoint(point); #elif defined(USE_X11) int x, y; /* This is all we care about. Seriously. */ Window garb1, garb2; /* Why you can't specify NULL as a parameter */ int garb_x, garb_y; /* is beyond me. */ unsigned int more_garbage; Display *display = XGetMainDisplay(); XQueryPointer(display, XDefaultRootWindow(display), &amp;garb1, &amp;garb2, &amp;x, &amp;y, &amp;garb_x, &amp;garb_y, &amp;more_garbage); return MMPointMake(x, y); #elif defined(IS_WINDOWS) POINT point; GetCursorPos(&amp;point); return MMPointFromPOINT(point); #endif } </code></pre> <p>This code seems to include a method of returning the mouse position in all operating systems, which is what I'm trying to implement in my program. How can I get this c function to work properly on my system, so that I can implement it in my program?</p> <p><b>EDIT:</b> I tried simply compiling mouse.c by using 'gcc mouse.c', and I'm getting this error:</p> <pre><code>Undefined symbols for architecture x86_64: "_CFRelease", referenced from: _moveMouse in ccVkh5f7.o _getMousePos in ccVkh5f7.o _toggleMouse in ccVkh5f7.o "_CGEventCreate", referenced from: _getMousePos in ccVkh5f7.o "_CGEventCreateMouseEvent", referenced from: _moveMouse in ccVkh5f7.o _toggleMouse in ccVkh5f7.o "_CGEventGetLocation", referenced from: _getMousePos in ccVkh5f7.o "_CGEventPost", referenced from: _moveMouse in ccVkh5f7.o _toggleMouse in ccVkh5f7.o "_deadbeef_rand", referenced from: _smoothlyMoveMouse in ccVkh5f7.o "_getMainDisplaySize", referenced from: _smoothlyMoveMouse in ccVkh5f7.o "_main", referenced from: start in crt1.10.6.o ld: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status </code></pre> <p>Does this make any underlying problem apparent?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload