1
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
2
# See LICENSE for details.
5
"""Logictech MouseMan serial protocol.
7
http://www.softnco.demon.co.uk/SerialMouse.txt
10
from twisted.internet import protocol
12
class MouseMan(protocol.Protocol):
15
Parser for Logitech MouseMan serial mouse protocol (compatible
16
with Microsoft Serial Mouse).
41
def down_middle(self):
59
def state_initial(self, byte):
62
self.leftbutton = byte & 1<<5
63
self.rightbutton = byte & 1<<4
68
def state_horiz(self, byte):
70
return self.state_initial(byte)
72
x=(self.word1 & 0x03)<<6 | (byte & 0x3f)
78
def state_vert(self, byte):
81
return self.state_initial(byte)
83
x = (self.word1 & 0x0c)<<4 | (byte & 0x3f)
90
def state_maybemiddle(self, byte):
93
return self.state_initial(byte)
95
self.middlebutton=byte & 1<<5
100
if self.leftbutton and not self.leftold:
103
if not self.leftbutton and self.leftold:
107
if self.middlebutton and not self.middleold:
110
if not self.middlebutton and self.middleold:
114
if self.rightbutton and not self.rightold:
117
if not self.rightbutton and self.rightold:
121
if self.horiz or self.vert:
122
self.move(self.horiz, self.vert)
124
def dataReceived(self, data):
127
self.state = getattr(self, 'state_'+self.state)(byte)