tests/mouse.py
changeset 20 472a753664f9
parent 19 5e78d52ebb24
child 21 8553a6bd2d82
equal deleted inserted replaced
19:5e78d52ebb24 20:472a753664f9
     1 #!/usr/bin/python
       
     2 # -*- coding: utf-8 -*-
       
     3 
       
     4 import curses
       
     5 import locale
       
     6 
       
     7 locale.setlocale(locale.LC_ALL,"")
       
     8 
       
     9 def doStuff(screen):
       
    10     screen.addstr('%s\n' % curses.termname())
       
    11     screen.keypad(1)
       
    12     screen.scrollok(1)
       
    13     curses.nl()
       
    14     curses.mousemask(curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION)
       
    15     curses.mouseinterval(0)  # do not wait to detect clicks, we use only press/release
       
    16     while True:
       
    17         c = screen.getch()
       
    18         char = ' '
       
    19         if c < 256:
       
    20             char = curses.unctrl(c)
       
    21         screen.addstr('key: %x %s\n' % (c, char))
       
    22 
       
    23         if c == curses.KEY_MOUSE:
       
    24             m = curses.getmouse()
       
    25             screen.addstr('(%d %d %d %d %x)\n' % m)
       
    26 
       
    27         screen.refresh()
       
    28 
       
    29 curses.wrapper(doStuff)