I'm making a simple applet in Common Lisp and I want to control it using mouse movement. I use LTK for the window. I couldn't find any function that would retrieve the mouse location. For example, Emacs Lisp has (mouse-pixel-position). I found this on rosetta code, but there's no Common Lisp entry. What can I do?
Common Lisp mouse position with ltk
314 Views Asked by Kotlopou At
2
There are 2 best solutions below
0
On
An event-based approach is likely to be more appropriate in most cases, but you can also query the current position directly:
(defpackage :so (:use :cl :ltk))
(in-package :so)
(with-ltk ()
(loop
(print
(multiple-value-list
(screen-mouse)))
(sleep 0.5)))
This starts a graphical toplevel and prints the current screen coordinates every 500ms, until you quit the toplevel window. The screen-mouse function accepts an optional w argument (a window).
Hints from this SO answer: Mouse Position Python Tkinter
and looking at ltk's doc: http://www.peter-herth.de/ltk/ltkdoc/node16.html
I got the following example to retrieve any event fired by the mouse movement:
This opens up a little window with nothing inside. Once you put the mouse in it, you get lots of events:
The
#Sindicates we deal with a structure, namedEVENT, so we can access its slots with(event-x event),event-mouse-button, etc. See https://lispcookbook.github.io/cl-cookbook/data-structures.html#slot-accessAlso you might want to join the CL community on freenode, there are some game developers there.