How to get mouse wheel verdict with Python curses

environment

Introduction

I made it myself because curses didn't have mouse wheel judgment.

Before reading this, please read this article.

Symptoms

I can't get a wheel judgment

Cause

Curses provides mouse click judgment, etc., but it is insufficient, and wheel judgment. In particular, there is no judgment when scrolling down.

solution

For comments on the judgment part, refer to the article on Japanese input. Pseudo code. You haven't declared the window object properly

import curses

window = curses.stdscr()
key = window.getch()

text_pool = [key]
if 0x00 <= key <= 0x7f:
     pass
elif 0x80 <= key <= 0xbf:
     print(key)
     exit(1)
elif 0xc0 <= key <= 0xdf:
     text_pool.append(self.window.getch())
     a, b = text_pool
     tmp = map(lambda x: bin(x)[2:], [0b00011111 & a, 0b00111111 & b])
     tmp = ''.join(item.zfill(6) for item in tmp)
     key = int(tmp,2)
elif 0xe0 <= key <= 0xef:
     for _ in range(2):
         text_pool.append(self.window.getch())
         a, b, c = text_pool
         tmp = map(lambda x: bin(x)[2:], [0b00001111 & a, 0b00111111 & b, 0b00111111 & c])
         tmp = ''.join([item.zfill(6) for item in tmp])
     key = int(tmp,2)
elif 0xf0 <= key <= 0xff:
     for _ in range(3):
         text_pool.append(self.window.getch())
         a, b, c ,d = text_pool
         tmp = map(lambda x: bin(x)[2:], [0b00000111 & a, 0b00111111 & b, 0b00111111 & c, 0b00111111 & d])
         tmp = ''.join([item.zfill(6) for item in tmp])
     key = int(tmp,2)
else:
    pass

#Actual value
WHEEL_UP = 65536
WHEEL_DOWN = 2097152

if key == curses.KEY_MOUSE:
                #The integer entered by the mouse is stored here
                wheel = curses.getmouse()[4]
                if wheel == self.WHEEL_UP:
                    wheel_up_process()
                elif wheel == self.WHEEL_DOWN:
                    wheel_down_process()
else:
    print(chr(key)

reference

Recommended Posts

How to get mouse wheel verdict with Python curses
How to get started with Python
How to enter Japanese with Python curses
Python: How to use async with
Link to get started with python
How to get the Python version
How to get started with Scrapy
How to get started with Django
How to use FTP with Python
How to calculate date with python
How to get into the python development environment with Vagrant
[Introduction to Python] How to get data with the listdir function
How to get parent id with sqlalchemy
How to work with BigQuery in Python
How to do portmanteau test with python
How to display python Japanese with lolipop
[Python] How to get a value with a key other than value with Enum
[Python] How to deal with module errors
How Python beginners get started with Python with Progete
How to get started with laravel (Linux)
How to install python3 with docker centos
[Yahoo! Weather Replacement Version] How to get weather information with LINE Notify + Python
How to get the date and time difference in seconds with python
How to read a CSV file with Python 2/3
How to enjoy programming with Minecraft (Ruby, Python)
[REAPER] How to play with Reascript in Python
How to do multi-core parallel processing with python
Strategy on how to monetize with Python Java
[Python] How to draw multiple graphs with Matplotlib
[Python] How to read excel file with pandas
How to crop an image with Python + OpenCV
I tried to get CloudWatch data with Python
How to specify attributes with Mock of python
How to measure execution time with Python Part 1
How to get dictionary type elements of Python 2.7
How to get the files in the [Python] folder
How to use tkinter with python in pyenv
[Python] How to handle Japanese characters with openCV
A layman wants to get started with Python
[Python] How to compare datetime with timezone added
Python script to get note information with REAPER
How to measure execution time with Python Part 2
How to install Python
How to install python
Get date with python
Note: How to get the last day of the month with python (added the first day of the month)
How to get a list of files in the same directory with python
[Introduction to Python] How to get the index of data with a for statement
How to convert / restore a string with [] in python
How to get the variable name itself in python
How to add help to HDA (with Python script bonus)
[First API] Try to get Qiita articles with Python
[Python] How to draw a line graph with Matplotlib
How to scrape image data from flickr with python
How to do hash calculation with salt in Python
[Introduction to Python] How to iterate with the range function?
Explain in detail how to make sounds with python
I tried to get started with blender python script_Part 01
How to get a logged-in user with Django's forms.py
How to run tests in bulk with Python unittest
[Python] How to specify the download location with youtube-dl