File: mouse_modifiers.py

package info (click to toggle)
python-blessed 1.25-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,812 kB
  • sloc: python: 14,645; makefile: 13; sh: 7
file content (27 lines) | stat: -rwxr-xr-x 948 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env python
from blessed import Terminal

term = Terminal()
counts = dict()

with term.fullscreen(), term.cbreak(), term.mouse_enabled():
    while True:
        inp = term.inkey(timeout=None)

        # Check if this is a mouse event
        if inp.name and inp.name.startswith('MOUSE_'):
            # Use the keystroke name for button identification
            counts[inp.name] = counts.get(inp.name, 0) + 1
            with term.synchronized_output():
                print(term.home + term.clear)
                print(term.bold("Mouse Modifier Example, press Ctrl+C to quit"))
                print()

                # Display the most recent event
                print(f"button={inp.name} at (y={inp.y}, x={inp.x})")
                print()

                # Display totals
                print("Totals: ")
                for button_name, count in sorted(counts.items()):
                    print(f"{button_name}: {count}")