0

I am using the following script Mouse Position Python Tkinter

to successfully print out my mouse coordinates on a Raspberry Pi running Raspbian. However, for the script to work I have to run it from the GUI. IS there any way for a Python script running outside of any desktop environment, to detect mouse coordinates and mouse clicks?

Community
  • 1
  • 1
Bachalo
  • 6,965
  • 27
  • 95
  • 189

2 Answers2

0

try using pygame and set videolibrary to dummy before pygame.init():

os.environ["SDL_VIDEODRIVER"] = "dummy"

this might work, but I haven't tested it.

yemu
  • 26,249
  • 10
  • 32
  • 29
0

I would try with module curses - it is made to work in terminal.

I found this example

import curses 

screen = curses.initscr() 
#curses.noecho() 
curses.curs_set(0) 
screen.keypad(1) 
curses.mousemask(1)

screen.addstr("Example\n\n") 

while True:
    event = screen.getch() 
    if event == ord("q"): 
        break 
    if event == curses.KEY_MOUSE:
        _, mx, my, _, _ = curses.getmouse()
        screen.addstr( '%d %d\n' % (mx, my) )

curses.endwin()
furas
  • 134,197
  • 12
  • 106
  • 148
  • All I see is 'Example' when i run this...no mouse coordinates. – Bachalo Jul 03 '14 at 19:20
  • I forgot to say - click mouse. – furas Jul 03 '14 at 19:55
  • :) Yes I figured as much, still nada. Maybe something to do with mousemask? – Bachalo Jul 03 '14 at 19:58
  • Let's try `screen.addstr()` in place of `print()` - see answer again. Does program end working when you press `q` on keyboard ? I test it with Python 2.7.5 and Python 3.3.2 but only on Linux Mint (based on Ubuntu/Debian) – furas Jul 03 '14 at 20:16