I made it myself because curses didn't have mouse wheel judgment.
Before reading this, please read this article.
I can't get a wheel judgment
Curses provides mouse click judgment, etc., but it is insufficient, and wheel judgment. In particular, there is no judgment when scrolling down.
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)
Recommended Posts