python 控制鼠标滚轮_Python诅咒中的鼠标滚轮

我想这是系统和终端相关的。我写了下面的它只是捕捉鼠标的状态并把它们打印到屏幕上。我能够在macosx中使用xterm接收鼠标滚动事件。(向上滚动注册为按钮4;向下滚动为按钮2,但使用本机终端应用程序时不起作用。)

如果您仔细查看这段代码,您必须首先使用scr.getch(),然后测试它是否返回{}。如果是这样,那么可以调用^{},它返回一个包含设备id、坐标和状态标志的元组。在import curses

from contextlib import contextmanager

@contextmanager

def open_screen():

scr = curses.initscr()

curses.noecho()

curses.cbreak()

scr.keypad(1)

try:

yield scr

finally:

curses.nocbreak()

scr.keypad(0)

curses.echo()

curses.endwin()

curses_mouse_states = {

curses.BUTTON1_PRESSED: 'Button 1 Pressed',

curses.BUTTON1_RELEASED: 'Button 1 Released',

curses.BUTTON1_CLICKED: 'Button 1 Clicked',

curses.BUTTON1_DOUBLE_CLICKED: 'Button 1 Double-Clicked',

curses.BUTTON1_TRIPLE_CLICKED: 'Button 1 Triple-Clicked',

curses.BUTTON2_PRESSED: 'Button 2 Pressed',

curses.BUTTON2_RELEASED: 'Button 2 Released',

curses.BUTTON2_CLICKED: 'Button 2 Clicked',

curses.BUTTON2_DOUBLE_CLICKED: 'Button 2 Double-Clicked',

curses.BUTTON2_TRIPLE_CLICKED: 'Button 2 Triple-Clicked',

curses.BUTTON3_PRESSED: 'Button 3 Pressed',

curses.BUTTON3_RELEASED: 'Button 3 Released',

curses.BUTTON3_CLICKED: 'Button 3 Clicked',

curses.BUTTON3_DOUBLE_CLICKED: 'Button 3 Double-Clicked',

curses.BUTTON3_TRIPLE_CLICKED: 'Button 3 Triple-Clicked',

curses.BUTTON4_PRESSED: 'Button 4 Pressed',

curses.BUTTON4_RELEASED: 'Button 4 Released',

curses.BUTTON4_CLICKED: 'Button 4 Clicked',

curses.BUTTON4_DOUBLE_CLICKED: 'Button 4 Double-Clicked',

curses.BUTTON4_TRIPLE_CLICKED: 'Button 4 Triple-Clicked',

curses.BUTTON_SHIFT: 'Button Shift',

curses.BUTTON_CTRL: 'Button Ctrl',

curses.BUTTON_ALT: 'Button Alt'

}

with open_screen() as scr:

curses.mousemask(-1)

while True:

c = scr.getch()

if c == curses.KEY_MOUSE:

mouse_state = curses.getmouse()[4]

states = '; '.join(state_string for state, state_string

in curses_mouse_states.viewitems()

if mouse_state & state)

scr.addstr(0, 0, states)

scr.clrtoeol()

scr.refresh()

elif c == ord('q'):

break

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值