Permalink
Browse files

first pass at working code

  • Loading branch information...
1 parent 992c9d7 commit e9526e90f048db957820937d5de5fbf01cd4d222 Marc Sibson committed Dec 15, 2010
Showing with 1,742 additions and 0 deletions.
  1. +19 −0 LICENSE.txt
  2. +25 −0 README.txt
  3. +5 −0 scripts/vncdotool
  4. +41 −0 setup.py
  5. 0 vncdotool/__init__.py
  6. +62 −0 vncdotool/client.py
  7. +77 −0 vncdotool/command.py
  8. +852 −0 vncdotool/pyDes.py
  9. +661 −0 vncdotool/rfb.py
View
@@ -0,0 +1,19 @@
+Copyright (c) 2010 Marc Sibson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
View
@@ -5,3 +5,28 @@ the command line.
Currently under developement and altogether not ready for general use. One
day it might actually be useful.
+
+Quick Start
+--------------------------------
+Assuming you have a VNC server already running you can quickly try out
+vncdotool by running::
+
+ python vncdotool -h hostaddr -d displaynum click 2
+
+Which for most window managers will open a context menu at the top left
+corner of the screen.
+
+Usage
+--------------------------------
+
+Acknowledgements
+--------------------------------
+Thanks to
+
+(c) 2003 chris <cliechti@gmx.net>
+(c) 2009 techtonik <techtonik@gmail.com>
+
+
+whose python-vnc-viewer_, provided the RFB protocol implementation used by vncdotool.
+
+_python-vnc_viewer: http://code.google.com/p/python-vnc-viewer/
View
@@ -0,0 +1,5 @@
+#!/usr/bin/env python
+from vncdotool.command import main
+
+if __name__ == '__main__':
+ main()
View
@@ -0,0 +1,41 @@
+#!/usr/bin/env python
+
+from distutils.core import setup
+
+setup(
+ name='vncdotool',
+ version='0.1.0dev',
+ description='Send keyboard and mouse events to a VNC server from the command line',
+ requires=[
+ 'Twisted',
+ ],
+
+ url='http://github.com/sibson/vncdotool',
+ author='Marc Sibson',
+ author_email='sibson+vncdotool@gmail.com',
+ download_url='',
+
+ scripts=['scripts/vncdotool'],
+ packages=['vncdotool'],
+
+ classifiers=[
+ 'Development Status :: 2 - Pre-Alpha',
+ 'Environment :: Console',
+ 'Framework :: Twisted',
+ 'Intended Audience :: Developers',
+ 'Intended Audience :: System Administrators',
+ 'License :: OSI Approved :: MIT License',
+ 'Operating System :: MacOS :: MacOS X',
+ 'Operating System :: Microsoft :: Windows',
+ 'Operating System :: POSIX',
+ 'Programming Language :: Python',
+ 'Programming Language :: Python :: 2.4',
+ 'Programming Language :: Python :: 2.5',
+ 'Programming Language :: Python :: 2.6',
+ 'Programming Language :: Python :: 2.7',
+ 'Topic :: Multimedia :: Graphics :: Viewers',
+ 'Topic :: Software Development :: Testing',
+ ],
+
+ long_description='',
+)
No changes.
View
@@ -0,0 +1,62 @@
+"""
+
+(c) 2010 Marc Sibson
+
+MIT License
+"""
+
+from rfb import RFBClient, RFBFactory
+from twisted.internet import reactor
+from twisted.internet.defer import Deferred
+
+
+class VNCDoToolClient(RFBClient):
+ x = 0
+ y = 0
+
+ def vncConnectionMade(self):
+ self.setPixelFormat()
+ self.factory.deferred.callback(self)
+
+ def keyPress(self, key):
+ self.keyEvent(ord(key), down=1)
+ self.keyEvent(ord(key), down=0)
+ return self
+
+ def mousePress(self, button):
+ buttons = 1 << button
+ self.pointerEvent(self.x, self.y, buttonmask=buttons)
+ self.pointerEvent(self.x, self.y, buttonmask=0)
@pevogam
pevogam Sep 22, 2015

Just want to report that after running this with my setup (qemu+vnc) the mouse button stays down and hangs forever. A current workaround I found was to call mouseUp after this. Interestingly, the problem also seems to appear only for the left button (1). I used strace and internal debugging and didn't find any mistake in this code so I assume it might be external error but I think it's good to inform you.

+ return self
+
+
+ def mouseMove(self, x, y):
+ self.x, self.y = x, y
+ self.pointerEvent(x, y)
+ return self
+
+ def bell(self):
+ print 'ding'
+
+ def copy_text(self, text):
+ print 'clip', repr(text)
+
+ def paste(self, message):
+ self.clientCutText(message)
+ return self
+
+
+class VNCDoToolFactory(RFBFactory):
+ protocol = VNCDoToolClient
+ password = None
+ shared = 1
+
+ def __init__(self):
+ self.deferred = Deferred()
+
+ def clientConnectionFailed(self, connector, reason):
+ print 'connection failed', reason
+ reactor.callLater(0, self.deferred.errback, reason)
+ self.deferred = None
+
+
View
@@ -0,0 +1,77 @@
+#!/usr/bin/env python
+"""
+
+(c) 2010 Marc Sibson
+
+MIT License
+"""
+import optparse
+
+from twisted.internet import reactor
+
+from vncdotool.client import VNCDoToolFactory, VNCDoToolClient
+
+def log_connected(pcol):
+ print 'connected to', pcol.name
+ return pcol
+
+
+def log_failed(reason):
+ print 'connection failed', reason.getErrorMesssage()
+
+
+def stop(pcol):
+ pcol.transport.loseConnection()
+ reactor.callLater(0.1, reactor.stop)
+
+def main():
+ op = optparse.OptionParser(usage='%prog [options] cmd',
+ add_help_option=False)
+ op.add_option('-d', '--display', action='store', metavar='DISPLAY',
+ type='int', default=0,
+ help='connect to vnc server on DISPLAY [%default]')
+ op.add_option('--help', action='help',
+ help='show this help message')
+ op.add_option('-h', '--host', action='store', metavar='HOST',
+ default='127.0.0.1',
+ help='connect to vnc server at HOST [%default]')
+ op.add_option('-p', '--port', action='store', metavar='PORT',
+ type='int',
+ help='connect to vnc server on PORT')
+ op.add_option('-v', '--verbose', action='store_true')
+
+ opts, args = op.parse_args()
+ if opts.port is None:
+ opts.port = opts.display + 5900
+
+ if not len(args):
+ op.error('no command provided')
+
+ f = VNCDoToolFactory()
+ if opts.verbose:
+ print 'connecting to %s:%d' % (opts.host, opts.port)
+
+ if opts.verbose:
+ f.deferred.addCallbacks(log_connected, log_failed)
+
+ while args:
+ cmd = args.pop(0)
+ if cmd == 'key':
+ f.deferred.addCallback(VNCDoToolClient.keyPress, args.pop(0))
+ elif cmd == 'move':
+ x, y = int(args.pop(0)), int(args.pop(0))
+ f.deferred.addCallback(VNCDoToolClient.mouseMove, x, y)
+ elif cmd == 'click':
+ button = int(args.pop(0))
+ f.deferred.addCallback(VNCDoToolClient.mousePress, button)
+ elif cmd == 'type':
+ for key in args.pop(0):
+ f.deferred.addCallback(VNCDoToolClient.keyPress, key)
+
+ f.deferred.addCallback(stop)
+
+ reactor.connectTCP(opts.host, opts.port, f)
+ reactor.run()
+
+if __name__ == '__main__':
+ main()
Oops, something went wrong.

0 comments on commit e9526e9

Please sign in to comment.