Skip to content
Sign upLog in
← Back to Community

python mouse position?

Profile icon
skull_is_dull

is it possible to return a mouses x and y position in python?

Answered by PYer [earned 5 cycles]
View Answer
Voters
Profile icon
TimothyWieland
Profile icon
skull_is_dull
Comments
hotnewtop
Profile icon
PYer

This using

@mat1
xterm module:
clicks.py

import xterm printing = False def getclicks(): for char in xterm.readchrs(): if type(char)!=str: x = char.x y = char.y yield (x, y, char)

main.py

import clicks coords = clicks.getclicks()

There may be a few edits from the original because I have modified it to suit me.

The module yields only within the terminal and the top left of the terminal is (0, 0)
Please upvote if this was useful thanks!

Profile icon
Scoder12

What do you mean? In the terminal? Where do you want to capture the mouse position from?