The function called by the Python example seems to be documented here. It is part of a shared library user32.dll
, which you can load with CFFI,
(ql:quickload :cffi)
#+win32
(progn
(cffi:define-foreign-library user32
(:windows "user32.dll"))
(cffi:use-foreign-library user32))
The #+win32
means that this is only evaluated on Windows.
Then you can declare the foreign SetCursorPos
-function with CFFI:DEFCFUN
. According to the documentation, it takes in two int
s and returns a BOOL
. CFFI has a :BOOL
-type, however the Windows BOOL
seems to actually be an int
. You could probably use cffi-grovel to automatically find the typedef from some Windows header, but I'll just use :INT
directly here.
#+win32
(cffi:defcfun ("SetCursorPos" %set-cursor-pos) (:boolean :int)
(x :int)
(y :int))
I put a %
in the name to indicate this is an internal function that should not be called directly (because it is only available on Windows). You should then write a wrapper that works on different platforms (actually implementing it on other platforms is left out here).
(defun set-cursor-pos (x y)
(check-type x integer)
(check-type y integer)
#+win32 (%set-cursor-pos x y)
#-win32 (error "Not supported on this platform"))
Now calling (set-cursor-pos 100 100)
should move the mouse near the top left corner.