Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add mouseup and mousedown commands

  • Loading branch information...
commit bee7132262c2ca7216ad2f2e19af84b118365857 1 parent d69fccd
@sibson authored
View
2  NEWS.txt
@@ -1,6 +1,6 @@
vncdotool - 0.2.0 (unreleased)
--------------------------------
- - add pause command
+ - add pause, mouseup, mousedown commands
vncdotool - 0.1.1 (2011-05-18)
--------------------------------
View
15 tests/unit/test_command.py
@@ -88,6 +88,21 @@ def test_chain_type_expect(self):
def test_pause(self):
self.call_build_commands_list('pause 0.3')
self.factory.deferred.addCallback.assert_called_with(command.pause, 0.3)
+ def test_mousedown(self):
+ self.call_build_commands_list('mousedown 1')
+ self.factory.deferred.addCallback.assert_called_with(self.client.mouseDown, 1)
+
+ self.call_build_commands_list('mdown 2')
+ self.factory.deferred.addCallback.assert_called_with(self.client.mouseDown, 2)
+
+ def test_mouseup(self):
+ self.call_build_commands_list('mouseup 1')
+ self.factory.deferred.addCallback.assert_called_with(self.client.mouseUp, 1)
+
+ self.call_build_commands_list('mup 2')
+ self.factory.deferred.addCallback.assert_called_with(self.client.mouseUp, 2)
+
+
@mock.isolate(command.main)
View
30 vncdotool/client.py
@@ -93,6 +93,7 @@
class VNCDoToolClient(rfb.RFBClient):
x = 0
y = 0
+ buttons = 0
screen = None
def keyPress(self, key):
@@ -120,12 +121,35 @@ def mousePress(self, button):
button: int: [1-n]
"""
- buttons = 1 << (button - 1)
+ buttons = self.buttons | (1 << (button - 1))
self.pointerEvent(self.x, self.y, buttonmask=buttons)
- self.pointerEvent(self.x, self.y, buttonmask=0)
+ self.pointerEvent(self.x, self.y, buttonmask=self.buttons)
return self
+ def mouseDown(self, button):
+ """ Send a mouse button down at the last set position
+
+ button: int: [1-n]
+
+ """
+ self.buttons |= 1 << (button - 1)
+ self.pointerEvent(self.x, self.y, buttonmask=self.buttons)
+
+ return self
+
+ def mouseUp(self, button):
+ """ Send mouse button released at the last set position
+
+ button: int: [1-n]
+
+ """
+ self.buttons &= ~(1 << (button - 1))
+ self.pointerEvent(self.x, self.y, buttonmask=self.buttons)
+
+ return self
+
+
def captureScreen(self, filename):
""" Save the current display to filename
"""
@@ -177,7 +201,7 @@ def mouseMove(self, x, y):
""" Move the mouse pointer to position (x, y)
"""
self.x, self.y = x, y
- self.pointerEvent(x, y)
+ self.pointerEvent(x, y, self.buttons)
return self
def log(self, fmt, *args):
View
8 vncdotool/command.py
@@ -50,6 +50,8 @@ def format_help(self, **kwargs):
' capture FILE:\tsave current screen as FILE',
' expect FILE FUZZ: Wait until the screen matches FILE',
'\t\tFUZZ amount of error tolerance (RMSE) in match',
+ ' mousedown BUTTON:\tsend BUTTON down',
+ ' mouseup BUTTON:\tsend BUTTON up',
' pause DURATION:\twait DURATION seconds before sending next',
'',
])
@@ -74,6 +76,12 @@ def build_command_list(factory, args):
elif cmd == 'click':
button = int(args.pop(0))
factory.deferred.addCallback(client.mousePress, button)
+ elif cmd in ('mdown', 'mousedown'):
+ button = int(args.pop(0))
+ factory.deferred.addCallback(client.mouseDown, button)
+ elif cmd in ('mup', 'mouseup'):
+ button = int(args.pop(0))
+ factory.deferred.addCallback(client.mouseUp, button)
elif cmd == 'type':
for key in args.pop(0):
factory.deferred.addCallback(client.keyPress, key)
Please sign in to comment.
Something went wrong with that request. Please try again.