├── .gitattributes ├── .gitignore ├── .travis.yml ├── LICENSE.txt ├── MANIFEST.in ├── Makefile ├── README.rst ├── build-dist.bat ├── build-doc.bat ├── create_doctree.py ├── install-win.bat ├── macro ├── __init__.py ├── bot.py └── zzz_manual_install.py ├── make.bat ├── pypi-register.bat ├── pypi-upload.bat ├── recipe └── might_and_magic_VI.py ├── release-history.rst ├── requirements.txt ├── setup.py ├── source ├── _static │ └── macro-logo.jpg ├── about.rst ├── bot │ ├── content.rst │ └── index.rst ├── conf.py ├── content.rst ├── index.rst └── macro │ ├── __init__.rst │ ├── bot.rst │ └── dec.rst ├── tests └── test_bot.py └── view-doc.bat /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask instance folder 57 | instance/ 58 | 59 | # Scrapy stuff: 60 | .scrapy 61 | 62 | # Sphinx documentation 63 | docs/_build/ 64 | 65 | # PyBuilder 66 | target/ 67 | 68 | # IPython Notebook 69 | .ipynb_checkpoints 70 | 71 | # pyenv 72 | .python-version 73 | 74 | # celery beat schedule file 75 | celerybeat-schedule 76 | 77 | # dotenv 78 | .env 79 | 80 | # virtualenv 81 | venv/ 82 | ENV/ 83 | 84 | # Spyder project settings 85 | .spyderproject 86 | 87 | # Rope project settings 88 | .ropeproject 89 | 90 | # ========================= 91 | # Operating System Files 92 | # ========================= 93 | 94 | # OSX 95 | # ========================= 96 | 97 | .DS_Store 98 | .AppleDouble 99 | .LSOverride 100 | 101 | # Thumbnails 102 | ._* 103 | 104 | # Files that might appear in the root of a volume 105 | .DocumentRevisions-V100 106 | .fseventsd 107 | .Spotlight-V100 108 | .TemporaryItems 109 | .Trashes 110 | .VolumeIcon.icns 111 | 112 | # Directories potentially created on remote AFP share 113 | .AppleDB 114 | .AppleDesktop 115 | Network Trash Folder 116 | Temporary Items 117 | .apdisk 118 | 119 | # Windows 120 | # ========================= 121 | 122 | # Windows image file caches 123 | Thumbs.db 124 | ehthumbs.db 125 | 126 | # Folder config file 127 | Desktop.ini 128 | 129 | # Recycle Bin used on file shares 130 | $RECYCLE.BIN/ 131 | 132 | # Windows Installer files 133 | *.cab 134 | *.msi 135 | *.msm 136 | *.msp 137 | 138 | # Windows shortcuts 139 | *.lnk 140 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - "2.7" 4 | - "3.3" 5 | - "3.4" 6 | - "3.5" 7 | install: 8 | - pip install PyUserInput 9 | - pip install pyperclip 10 | - pip install . # Install it self 11 | script: py.test -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright 2016 Sanhe Hu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.rst LICENSE.txt requirements.txt release_history.rst 2 | recursive-include macro *.* -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = build 9 | 10 | # User-friendly check for sphinx-build 11 | ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) 12 | $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) 13 | endif 14 | 15 | # Internal variables. 16 | PAPEROPT_a4 = -D latex_paper_size=a4 17 | PAPEROPT_letter = -D latex_paper_size=letter 18 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source 19 | # the i18n builder cannot share the environment and doctrees with the others 20 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source 21 | 22 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest coverage gettext 23 | 24 | help: 25 | @echo "Please use \`make ' where is one of" 26 | @echo " html to make standalone HTML files" 27 | @echo " dirhtml to make HTML files named index.html in directories" 28 | @echo " singlehtml to make a single large HTML file" 29 | @echo " pickle to make pickle files" 30 | @echo " json to make JSON files" 31 | @echo " htmlhelp to make HTML files and a HTML help project" 32 | @echo " qthelp to make HTML files and a qthelp project" 33 | @echo " applehelp to make an Apple Help Book" 34 | @echo " devhelp to make HTML files and a Devhelp project" 35 | @echo " epub to make an epub" 36 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 37 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 38 | @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" 39 | @echo " text to make text files" 40 | @echo " man to make manual pages" 41 | @echo " texinfo to make Texinfo files" 42 | @echo " info to make Texinfo files and run them through makeinfo" 43 | @echo " gettext to make PO message catalogs" 44 | @echo " changes to make an overview of all changed/added/deprecated items" 45 | @echo " xml to make Docutils-native XML files" 46 | @echo " pseudoxml to make pseudoxml-XML files for display purposes" 47 | @echo " linkcheck to check all external links for integrity" 48 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 49 | @echo " coverage to run coverage check of the documentation (if enabled)" 50 | 51 | clean: 52 | rm -rf $(BUILDDIR)/* 53 | 54 | html: 55 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 56 | @echo 57 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 58 | 59 | dirhtml: 60 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 61 | @echo 62 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 63 | 64 | singlehtml: 65 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 66 | @echo 67 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 68 | 69 | pickle: 70 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 71 | @echo 72 | @echo "Build finished; now you can process the pickle files." 73 | 74 | json: 75 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 76 | @echo 77 | @echo "Build finished; now you can process the JSON files." 78 | 79 | htmlhelp: 80 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 81 | @echo 82 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 83 | ".hhp project file in $(BUILDDIR)/htmlhelp." 84 | 85 | qthelp: 86 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 87 | @echo 88 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 89 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 90 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/macro.qhcp" 91 | @echo "To view the help file:" 92 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/macro.qhc" 93 | 94 | applehelp: 95 | $(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp 96 | @echo 97 | @echo "Build finished. The help book is in $(BUILDDIR)/applehelp." 98 | @echo "N.B. You won't be able to view it unless you put it in" \ 99 | "~/Library/Documentation/Help or install it in your application" \ 100 | "bundle." 101 | 102 | devhelp: 103 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 104 | @echo 105 | @echo "Build finished." 106 | @echo "To view the help file:" 107 | @echo "# mkdir -p $$HOME/.local/share/devhelp/macro" 108 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/macro" 109 | @echo "# devhelp" 110 | 111 | epub: 112 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 113 | @echo 114 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 115 | 116 | latex: 117 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 118 | @echo 119 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 120 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 121 | "(use \`make latexpdf' here to do that automatically)." 122 | 123 | latexpdf: 124 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 125 | @echo "Running LaTeX files through pdflatex..." 126 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 127 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 128 | 129 | latexpdfja: 130 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 131 | @echo "Running LaTeX files through platex and dvipdfmx..." 132 | $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja 133 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 134 | 135 | text: 136 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 137 | @echo 138 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 139 | 140 | man: 141 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 142 | @echo 143 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 144 | 145 | texinfo: 146 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 147 | @echo 148 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 149 | @echo "Run \`make' in that directory to run these through makeinfo" \ 150 | "(use \`make info' here to do that automatically)." 151 | 152 | info: 153 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 154 | @echo "Running Texinfo files through makeinfo..." 155 | make -C $(BUILDDIR)/texinfo info 156 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 157 | 158 | gettext: 159 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 160 | @echo 161 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 162 | 163 | changes: 164 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 165 | @echo 166 | @echo "The overview file is in $(BUILDDIR)/changes." 167 | 168 | linkcheck: 169 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 170 | @echo 171 | @echo "Link check complete; look for any errors in the above output " \ 172 | "or in $(BUILDDIR)/linkcheck/output.txt." 173 | 174 | doctest: 175 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 176 | @echo "Testing of doctests in the sources finished, look at the " \ 177 | "results in $(BUILDDIR)/doctest/output.txt." 178 | 179 | coverage: 180 | $(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage 181 | @echo "Testing of coverage in the sources finished, look at the " \ 182 | "results in $(BUILDDIR)/coverage/python.txt." 183 | 184 | xml: 185 | $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml 186 | @echo 187 | @echo "Build finished. The XML files are in $(BUILDDIR)/xml." 188 | 189 | pseudoxml: 190 | $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml 191 | @echo 192 | @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." 193 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | .. image:: https://travis-ci.org/MacHu-GWU/macro-project.svg?branch=master 2 | 3 | .. image:: https://img.shields.io/pypi/v/macro.svg 4 | 5 | .. image:: https://img.shields.io/pypi/l/macro.svg 6 | 7 | .. image:: https://img.shields.io/pypi/pyversions/macro.svg 8 | 9 | 10 | Welcome to macro Documentation 11 | =============================================================================== 12 | macro provides very user friendly syntax to program your keyboard and mouse automate script. 13 | 14 | 15 | **Quick Links** 16 | ------------------------------------------------------------------------------- 17 | - `GitHub Homepage `_ 18 | - `Online Documentation `_ 19 | - `PyPI download `_ 20 | - `Install `_ 21 | - `Issue submit and feature request `_ 22 | - `API reference and source code `_ 23 | 24 | 25 | .. _install: 26 | 27 | Install 28 | ------------------------------------------------------------------------------- 29 | 30 | ``macro`` is released on PyPI, so all you need is: 31 | 32 | .. code-block:: console 33 | 34 | $ pip install macro 35 | 36 | To upgrade to latest version: 37 | 38 | .. code-block:: console 39 | 40 | $ pip install --upgrade macro -------------------------------------------------------------------------------- /build-dist.bat: -------------------------------------------------------------------------------- 1 | pushd "%~dp0" 2 | python3 setup.py sdist 3 | python3 setup.py bdist_wheel --universal 4 | pause -------------------------------------------------------------------------------- /build-doc.bat: -------------------------------------------------------------------------------- 1 | pushd "%~dp0" 2 | cd macro 3 | python3 zzz_manual_install.py 4 | cd .. 5 | python3 create_doctree.py 6 | make html -------------------------------------------------------------------------------- /create_doctree.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | import docfly 5 | 6 | # Uncomment this if you follow Sanhe's Sphinx Doc Style Guide 7 | #--- Manually Made Doc --- 8 | doc = docfly.DocTree("source") 9 | doc.fly() 10 | 11 | #--- Api Reference Doc --- 12 | package_name = "macro" 13 | 14 | doc = docfly.ApiReferenceDoc( 15 | package_name, 16 | dst="source", 17 | ignore=[ 18 | "%s.packages" % package_name, 19 | "%s.zzz_manual_install.py" % package_name, 20 | ] 21 | ) 22 | doc.fly() -------------------------------------------------------------------------------- /install-win.bat: -------------------------------------------------------------------------------- 1 | pushd "%~dp0" 2 | cd macro 3 | python3 zzz_manual_install.py -------------------------------------------------------------------------------- /macro/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | __version__ = "0.0.2" 5 | __short_description__ = "Automate keyboard and mouse scripting." 6 | __license__ = "MIT" 7 | __author__ = "Sanhe Hu" -------------------------------------------------------------------------------- /macro/bot.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | bot is this mouse and keyboard simulation module, built on top of 6 | PyUserInput/pymouse/pykeyboard/pywin32/pyperclip. 7 | """ 8 | 9 | import sys 10 | import time 11 | import string 12 | 13 | try: 14 | from pymouse import PyMouse 15 | from pykeyboard import PyKeyboard 16 | except ImportError as e: 17 | raise ImportError("please install PyUserInput!") 18 | 19 | try: 20 | import pyperclip 21 | except ImportError as e: 22 | raise ImportError("please install pyperclip!") 23 | 24 | 25 | class Bot(object): 26 | 27 | """Mouse and Keyboard robot class. 28 | 29 | Abbreviation table: 30 | 31 | - m: stands for mouse 32 | - k: stands for keyboard 33 | - dl: stands for delay 34 | - n: how many times you want to tap the key 35 | - i: usually for the ith function key, F1 ~ F12 36 | 37 | Almost every method have an option keyword ``dl`` (dl stands for delay), there 38 | is ``dl`` seconds delay applied at begin. By default it is ``None``, means no 39 | delay applied. 40 | 41 | Keyboard Key Name Table (Case Insensitive):: 42 | 43 | # Main Keyboard Keys 44 | "ctrl": self.k.control_key, 45 | "l_ctrl": self.k.control_l_key, 46 | "r_ctrl": self.k.control_r_key, 47 | "alt": self.k.alt_key, 48 | "l_alt": self.k.alt_l_key, 49 | "r_alt": self.k.alt_r_key, 50 | "shift": self.k.shift_key, 51 | "l_shift": self.k.shift_l_key, 52 | "r_shift": self.k.shift_r_key, 53 | "tab": self.k.tab_key, 54 | "space": self.k.space_key, 55 | "enter": self.k.enter_key, 56 | "back": self.k.backspace_key, 57 | "backspace": self.k.backspace_key, 58 | 59 | # Side Keyboard Keys 60 | "home": self.k.home_key, 61 | "end": self.k.end_key, 62 | "page_up": self.k.page_up_key, 63 | "pageup": self.k.page_up_key, 64 | "page_down": self.k.page_down_key, 65 | "page_down": self.k.page_down_key, 66 | "insert": self.k.insert_key, 67 | "ins": self.k.insert_key, 68 | "delete": self.k.delete_key, 69 | "del": self.k.delete_key, 70 | 71 | "up": self.k.up_key, 72 | "down": self.k.down_key, 73 | "left": self.k.left_key, 74 | "right": self.k.right_key, 75 | 76 | # Function Keys 77 | "f1": F1 78 | """ 79 | 80 | def __init__(self): 81 | self.m = PyMouse() 82 | self.k = PyKeyboard() 83 | self.dl = 0 84 | 85 | self._key_mapper = { 86 | # Main Keyboard Keys 87 | "ctrl": self.k.control_key, 88 | "l_ctrl": self.k.control_l_key, 89 | "r_ctrl": self.k.control_r_key, 90 | "alt": self.k.alt_key, 91 | "l_alt": self.k.alt_l_key, 92 | "r_alt": self.k.alt_r_key, 93 | "shift": self.k.shift_key, 94 | "l_shift": self.k.shift_l_key, 95 | "r_shift": self.k.shift_r_key, 96 | "tab": self.k.tab_key, 97 | "space": self.k.space_key, 98 | "enter": self.k.enter_key, 99 | "back": self.k.backspace_key, 100 | "backspace": self.k.backspace_key, 101 | 102 | # Side Keyboard Keys 103 | "home": self.k.home_key, 104 | "end": self.k.end_key, 105 | "page_up": self.k.page_up_key, 106 | "pageup": self.k.page_up_key, 107 | "page_down": self.k.page_down_key, 108 | "page_down": self.k.page_down_key, 109 | "insert": self.k.insert_key, 110 | "ins": self.k.insert_key, 111 | "delete": self.k.delete_key, 112 | "del": self.k.delete_key, 113 | 114 | "up": self.k.up_key, 115 | "down": self.k.down_key, 116 | "left": self.k.left_key, 117 | "right": self.k.right_key, 118 | 119 | # f1 - f12 is the function key 120 | } 121 | for i in range(1, 1+12): 122 | self._key_mapper["f%s" % i] = self.k.function_keys[i] 123 | 124 | def _parse_key(self, name): 125 | name = str(name) 126 | if name in string.printable: 127 | return name 128 | elif name.lower() in self._key_mapper: 129 | return self._key_mapper[name.lower()] 130 | else: 131 | raise ValueError( 132 | "%r is not a valid key name, use one of %s." % (name, list(self._key_mapper))) 133 | 134 | def delay(self, dl=0): 135 | """Delay for ``dl`` seconds. 136 | """ 137 | if dl is None: 138 | time.sleep(self.dl) 139 | elif dl < 0: 140 | sys.stderr.write( 141 | "delay cannot less than zero, this takes no effects.\n") 142 | else: 143 | time.sleep(dl) 144 | 145 | #--- Meta --- 146 | def get_screen_size(self): 147 | """Return screen's width and height in pixel. 148 | 149 | **中文文档** 150 | 151 | 返回屏幕的像素尺寸。 152 | """ 153 | width, height = self.m.screen_size() 154 | return width, height 155 | 156 | def get_position(self): 157 | """Return the current coordinate of mouse. 158 | 159 | **中文文档** 160 | 161 | 返回鼠标所处的位置坐标。 162 | """ 163 | x_axis, y_axis = self.m.position() 164 | return x_axis, y_axis 165 | 166 | #--- Mouse Macro --- 167 | def left_click(self, x, y, n=1, pre_dl=None, post_dl=None): 168 | """Left click at ``(x, y)`` on screen for ``n`` times. 169 | at begin. 170 | 171 | **中文文档** 172 | 173 | 在屏幕的 ``(x, y)`` 坐标处左键单击 ``n`` 次。 174 | """ 175 | self.delay(pre_dl) 176 | self.m.click(x, y, 1, n) 177 | self.delay(post_dl) 178 | 179 | def right_click(self, x, y, n=1, pre_dl=None, post_dl=None): 180 | """Right click at ``(x, y)`` on screen for ``n`` times. 181 | at begin. 182 | 183 | **中文文档** 184 | 185 | 在屏幕的 ``(x, y)`` 坐标处右键单击 ``n`` 次。 186 | """ 187 | self.delay(pre_dl) 188 | self.m.click(x, y, 2, n) 189 | self.delay(post_dl) 190 | 191 | def middle_click(self, x, y, n=1, pre_dl=None, post_dl=None): 192 | """Middle click at ``(x, y)`` on screen for ``n`` times. 193 | at begin. 194 | 195 | **中文文档** 196 | 197 | 在屏幕的 ``(x, y)`` 坐标处中键单击 ``n`` 次。 198 | """ 199 | self.delay(pre_dl) 200 | self.m.click(x, y, 3, n) 201 | self.delay(post_dl) 202 | 203 | def scroll_up(self, n, pre_dl=None, post_dl=None): 204 | """Scroll up ``n`` times. 205 | 206 | **中文文档** 207 | 208 | 鼠标滚轮向上滚动n次。 209 | """ 210 | self.delay(pre_dl) 211 | self.m.scroll(vertical=n) 212 | self.delay(post_dl) 213 | 214 | def scroll_down(self, n, pre_dl=None, post_dl=None): 215 | """Scroll down ``n`` times. 216 | 217 | **中文文档** 218 | 219 | 鼠标滚轮向下滚动n次。 220 | """ 221 | self.delay(pre_dl) 222 | self.m.scroll(vertical=-n) 223 | self.delay(post_dl) 224 | 225 | def scroll_right(self, n, pre_dl=None, post_dl=None): 226 | """Scroll right ``n`` times. 227 | 228 | **中文文档** 229 | 230 | 鼠标滚轮向右滚动n次(如果可能的话)。 231 | """ 232 | self.delay(pre_dl) 233 | self.m.scroll(horizontal=n) 234 | self.delay(post_dl) 235 | 236 | def scroll_left(self, n, pre_dl=None, post_dl=None): 237 | """Scroll left ``n`` times. 238 | 239 | **中文文档** 240 | 241 | 鼠标滚轮向左滚动n次(如果可能的话)。 242 | """ 243 | self.delay(pre_dl) 244 | self.m.scroll(horizontal=-n) 245 | self.delay(post_dl) 246 | 247 | def move_to(self, x, y, pre_dl=None, post_dl=None): 248 | """Move mouse to (x, y) 249 | 250 | **中文文档** 251 | 252 | 移动鼠标到 (x, y) 的坐标处。 253 | """ 254 | self.delay(pre_dl) 255 | self.m.move(x, y) 256 | self.delay(post_dl) 257 | 258 | def drag_and_release(self, start_x, start_y, end_x, end_y, pre_dl=None, post_dl=None): 259 | """Drag something from (start_x, start_y) to (end_x, endy) 260 | 261 | **中文文档** 262 | 263 | 从start的坐标处鼠标左键单击拖曳到end的坐标处 264 | start, end是tuple. 格式是(x, y) 265 | """ 266 | self.delay(pre_dl) 267 | self.m.press(start_x, start_y, 1) 268 | self.m.drag(end_x, end_y) 269 | self.m.release(end_x, end_y, 1) 270 | self.delay(post_dl) 271 | 272 | #--- Keyboard Single Key --- 273 | def tap_key(self, key_name, n=1, interval=0, pre_dl=None, post_dl=None): 274 | """Tap a key on keyboard for ``n`` times, with ``interval`` seconds of 275 | interval. Key is declared by it's name 276 | 277 | Example:: 278 | 279 | bot.tap_key("a") 280 | bot.tap_key(1) 281 | bot.tap_key("up") 282 | bot.tap_key("space") 283 | bot.tap_key("enter") 284 | bot.tap_key("tab") 285 | 286 | **中文文档** 287 | 288 | 以 ``interval`` 中定义的频率按下某个按键 ``n`` 次。接受按键名作为输入。 289 | """ 290 | key = self._parse_key(key_name) 291 | self.delay(pre_dl) 292 | self.k.tap_key(key, n, interval) 293 | self.delay(post_dl) 294 | 295 | def enter(self, n=1, interval=0, pre_dl=None, post_dl=None): 296 | """Press enter key n times. 297 | 298 | **中文文档** 299 | 300 | 按回车键/换行键 n 次。 301 | """ 302 | self.delay(pre_dl) 303 | self.k.tap_key(self.k.enter_key, n, interval) 304 | self.delay(post_dl) 305 | 306 | def backspace(self, n=1, interval=0, pre_dl=None, post_dl=None): 307 | """Press backspace key n times. 308 | 309 | **中文文档** 310 | 311 | 按退格键 n 次。 312 | """ 313 | self.delay(pre_dl) 314 | self.k.tap_key(self.k.backspace_key, n, interval) 315 | self.delay(post_dl) 316 | 317 | def space(self, n=1, interval=0, pre_dl=None, post_dl=None): 318 | """Press white space key n times. 319 | 320 | **中文文档** 321 | 322 | 按空格键 n 次。 323 | """ 324 | self.delay(pre_dl) 325 | self.k.tap_key(self.k.space_key, n) 326 | self.delay(post_dl) 327 | 328 | def fn(self, i, n=1, interval=0, pre_dl=None, post_dl=None): 329 | """Press Fn key n times. 330 | 331 | **中文文档** 332 | 333 | 按 Fn 功能键 n 次。 334 | """ 335 | self.delay(pre_dl) 336 | self.k.tap_key(self.k.function_keys[i], n, interval) 337 | self.delay(post_dl) 338 | 339 | def tab(self, n=1, interval=0, pre_dl=None, post_dl=None): 340 | """Tap ``tab`` key for ``n`` times, with ``interval`` seconds of interval. 341 | 342 | **中文文档** 343 | 344 | 以 ``interval`` 中定义的频率按下某个tab键 ``n`` 次。 345 | """ 346 | self.delay(pre_dl) 347 | self.k.tap_key(self.k.tab_key, n, interval) 348 | self.delay(post_dl) 349 | 350 | def up(self, n=1, interval=0, pre_dl=None, post_dl=None): 351 | """Press up key n times. 352 | 353 | **中文文档** 354 | 355 | 按上方向键 n 次。 356 | """ 357 | self.delay(pre_dl) 358 | self.k.tap_key(self.k.up_key, n, interval) 359 | self.delay(post_dl) 360 | 361 | def down(self, n=1, interval=0, pre_dl=None, post_dl=None): 362 | """Press down key n times. 363 | 364 | **中文文档** 365 | 366 | 按下方向键 n 次。 367 | """ 368 | self.delay(pre_dl) 369 | self.k.tap_key(self.k.down_key, n, interval) 370 | self.delay(post_dl) 371 | 372 | def left(self, n=1, interval=0, pre_dl=None, post_dl=None): 373 | """Press left key n times 374 | 375 | **中文文档** 376 | 377 | 按左方向键 n 次。 378 | """ 379 | self.delay(pre_dl) 380 | self.k.tap_key(self.k.left_key, n, interval) 381 | self.delay(post_dl) 382 | 383 | def right(self, n=1, interval=0, pre_dl=None, post_dl=None): 384 | """Press right key n times. 385 | 386 | **中文文档** 387 | 388 | 按右方向键 n 次。 389 | """ 390 | self.delay(pre_dl) 391 | self.k.tap_key(self.k.right_key, n, interval) 392 | self.delay(post_dl) 393 | 394 | def delete(self, n=1, interval=0, pre_dl=None, post_dl=None): 395 | """Pres delete key n times. 396 | 397 | **中文文档** 398 | 399 | 按 delete 键n次。 400 | """ 401 | self.delay(pre_dl) 402 | self.k.tap_key(self.k.delete_key, n, interval) 403 | self.delay(post_dl) 404 | 405 | def insert(self, n=1, interval=0, pre_dl=None, post_dl=None): 406 | """Pres insert key n times. 407 | 408 | **中文文档** 409 | 410 | 按 insert 键n次。 411 | """ 412 | self.delay(pre_dl) 413 | self.k.tap_key(self.k.insert_key, n, interval) 414 | self.delay(post_dl) 415 | 416 | def home(self, n=1, interval=0, pre_dl=None, post_dl=None): 417 | """Pres home key n times. 418 | 419 | **中文文档** 420 | 421 | 按 home 键n次。 422 | """ 423 | self.delay(pre_dl) 424 | self.k.tap_key(self.k.home_key, n, interval) 425 | self.delay(post_dl) 426 | 427 | def end(self, n=1, interval=0, pre_dl=None, post_dl=None): 428 | """Press end key n times. 429 | 430 | **中文文档** 431 | 432 | 按 end 键n次。 433 | """ 434 | self.delay(pre_dl) 435 | self.k.tap_key(self.k.end_key, n, interval) 436 | self.delay(post_dl) 437 | 438 | def page_up(self, n=1, interval=0, pre_dl=None, post_dl=None): 439 | """Pres page_up key n times. 440 | 441 | **中文文档** 442 | 443 | 按 page_up 键n次。 444 | """ 445 | self.delay(pre_dl) 446 | self.k.tap_key(self.k.page_up_key, n, interval) 447 | self.delay(post_dl) 448 | 449 | def page_down(self, n=1, interval=0, pre_dl=None, post_dl=None): 450 | """Pres page_down key n times. 451 | 452 | **中文文档** 453 | 454 | 按 page_down 键n次。 455 | """ 456 | self.delay(pre_dl) 457 | self.k.tap_key(self.k.page_down, n, interval) 458 | self.delay(post_dl) 459 | 460 | #--- Keyboard Combination --- 461 | def press_and_tap(self, press_key, tap_key, n=1, interval=0, pre_dl=None, post_dl=None): 462 | """Press combination of two keys, like Ctrl + C, Alt + F4. The second 463 | key could be tapped for multiple time. 464 | 465 | Examples:: 466 | 467 | bot.press_and_tap("ctrl", "c") 468 | bot.press_and_tap("shift", "1") 469 | 470 | **中文文档** 471 | 472 | 按下两个键的组合键。 473 | """ 474 | press_key = self._parse_key(press_key) 475 | tap_key = self._parse_key(tap_key) 476 | 477 | self.delay(pre_dl) 478 | self.k.press_key(press_key) 479 | self.k.tap_key(tap_key, n, interval) 480 | self.k.release_key(press_key) 481 | self.delay(post_dl) 482 | 483 | def press_two_and_tap(self, 484 | press_key1, press_key2, tap_key, n=1, interval=0, pre_dl=None, post_dl=None): 485 | """Press combination of three keys, like Ctrl + Shift + C, The tap key 486 | could be tapped for multiple time. 487 | 488 | Examples:: 489 | 490 | bot.press_and_tap("ctrl", "shift", "c") 491 | 492 | **中文文档** 493 | 494 | 按下三个键的组合键。 495 | """ 496 | press_key1 = self._parse_key(press_key1) 497 | press_key2 = self._parse_key(press_key2) 498 | tap_key = self._parse_key(tap_key) 499 | 500 | self.delay(pre_dl) 501 | self.k.press_key(press_key1) 502 | self.k.press_key(press_key2) 503 | self.k.tap_key(tap_key, n, interval) 504 | self.k.release_key(press_key1) 505 | self.k.release_key(press_key2) 506 | self.delay(post_dl) 507 | 508 | def ctrl_c(self, pre_dl=None, post_dl=None): 509 | """Press Ctrl + C, usually for copy. 510 | 511 | **中文文档** 512 | 513 | 按下 Ctrl + C 组合键, 通常用于复制。 514 | """ 515 | self.delay(pre_dl) 516 | self.k.press_key(self.k.control_key) 517 | self.k.tap_key("c") 518 | self.k.release_key(self.k.control_key) 519 | self.delay(post_dl) 520 | 521 | def ctrl_v(self, pre_dl=None, post_dl=None): 522 | """Press Ctrl + V, usually for paste. 523 | 524 | **中文文档** 525 | 526 | 按下 Ctrl + V 组合键, 通常用于粘贴。 527 | """ 528 | self.delay(pre_dl) 529 | self.k.press_key(self.k.control_key) 530 | self.k.tap_key("v") 531 | self.k.release_key(self.k.control_key) 532 | self.delay(post_dl) 533 | 534 | def ctrl_x(self, pre_dl=None, post_dl=None): 535 | """Press Ctrl + X, usually for cut. 536 | 537 | **中文文档** 538 | 539 | 按下 Ctrl + X 组合键, 通常用于剪切。 540 | """ 541 | self.delay(pre_dl) 542 | self.k.press_key(self.k.control_key) 543 | self.k.tap_key("x") 544 | self.k.release_key(self.k.control_key) 545 | self.delay(post_dl) 546 | 547 | def ctrl_z(self, pre_dl=None, post_dl=None): 548 | """Press Ctrl + Z, usually for undo. 549 | 550 | **中文文档** 551 | 552 | 按下 Ctrl + Z 组合键, 通常用于撤销上一次动作。 553 | """ 554 | self.delay(pre_dl) 555 | self.k.press_key(self.k.control_key) 556 | self.k.tap_key("z") 557 | self.k.release_key(self.k.control_key) 558 | self.delay(post_dl) 559 | 560 | def ctrl_y(self, pre_dl=None, post_dl=None): 561 | """Press Ctrl + Y, usually for redo. 562 | 563 | **中文文档** 564 | 565 | 按下 Ctrl + Y 组合键, 通常用于重复上一次动作。 566 | """ 567 | self.delay(pre_dl) 568 | self.k.press_key(self.k.control_key) 569 | self.k.tap_key("y") 570 | self.k.release_key(self.k.control_key) 571 | self.delay(post_dl) 572 | 573 | def ctrl_a(self, pre_dl=None, post_dl=None): 574 | """Press Ctrl + A, usually for select all. 575 | 576 | **中文文档** 577 | 578 | 按下 Ctrl + A 组合键, 通常用于选择全部。 579 | """ 580 | self.delay(pre_dl) 581 | self.k.press_key(self.k.control_key) 582 | self.k.tap_key("a") 583 | self.k.release_key(self.k.control_key) 584 | self.delay(post_dl) 585 | 586 | def ctrl_f(self, pre_dl=None, post_dl=None): 587 | """Press Ctrl + F, usually for search. 588 | 589 | **中文文档** 590 | 591 | 按下 Ctrl + F 组合键, 通常用于搜索。 592 | """ 593 | self.delay(pre_dl) 594 | self.k.press_key(self.k.control_key) 595 | self.k.tap_key("f") 596 | self.k.release_key(self.k.control_key) 597 | self.delay(post_dl) 598 | 599 | def ctrl_fn(self, i, pre_dl=None, post_dl=None): 600 | """Press Ctrl + Fn1 ~ 12 once. 601 | 602 | **中文文档** 603 | 604 | 按下 Ctrl + Fn1 ~ 12 组合键。 605 | """ 606 | self.delay(pre_dl) 607 | self.k.press_key(self.k.control_key) 608 | self.k.tap_key(self.k.function_keys[i]) 609 | self.k.release_key(self.k.control_key) 610 | self.delay(post_dl) 611 | 612 | def alt_fn(self, i, pre_dl=None, post_dl=None): 613 | """Press Alt + Fn1 ~ 12 once. 614 | 615 | **中文文档** 616 | 617 | 按下 Alt + Fn1 ~ 12 组合键。 618 | """ 619 | self.delay(pre_dl) 620 | self.k.press_key(self.k.alt_key) 621 | self.k.tap_key(self.k.function_keys[i]) 622 | self.k.release_key(self.k.alt_key) 623 | self.delay(post_dl) 624 | 625 | def shift_fn(self, i, pre_dl=None, post_dl=None): 626 | """Press Shift + Fn1 ~ 12 once. 627 | 628 | **中文文档** 629 | 630 | 按下 Shift + Fn1 ~ 12 组合键。 631 | """ 632 | self.delay(pre_dl) 633 | self.k.press_key(self.k.shift_key) 634 | self.k.tap_key(self.k.function_keys[i]) 635 | self.k.release_key(self.k.shift_key) 636 | self.delay(post_dl) 637 | 638 | def alt_tab(self, n=1, pre_dl=None, post_dl=None): 639 | """Press Alt + Tab once, usually for switching between windows. 640 | Tab can be tapped for n times, default once. 641 | 642 | **中文文档** 643 | 644 | 按下 Alt + Tab 组合键, 其中Tab键按 n 次, 通常用于切换窗口。 645 | """ 646 | self.delay(pre_dl) 647 | self.k.press_key(self.k.alt_key) 648 | self.k.tap_key(self.k.tab_key, n=n, interval=0.1) 649 | self.k.release_key(self.k.alt_key) 650 | self.delay(post_dl) 651 | 652 | #--- Other --- 653 | def type_string(self, text, interval=0, pre_dl=None, post_dl=None): 654 | """Enter strings. 655 | 656 | **中文文档** 657 | 658 | 从键盘输入字符串, interval是字符间输入时间间隔, 单位是秒。 659 | """ 660 | self.delay(pre_dl) 661 | self.k.type_string(text, interval) 662 | self.delay(post_dl) 663 | 664 | def copy_text_to_clipboard(self, text): 665 | """Copy text to clipboard. 666 | 667 | **中文文档** 668 | 669 | 拷贝字符串到剪贴板。 670 | """ 671 | pyperclip.copy(text) 672 | 673 | 674 | bot = Bot() 675 | -------------------------------------------------------------------------------- /macro/zzz_manual_install.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | Copyright (c) 2014-2016 Sanhe Hu 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | """ 25 | 26 | from __future__ import print_function, unicode_literals 27 | import os 28 | import site 29 | import shutil 30 | import hashlib 31 | import platform 32 | 33 | __version__ = "0.0.1" 34 | __short_description__ = "Utility script to install your package in one shot, for developer." 35 | __author__ = "Sanhe Hu" 36 | 37 | SRC = os.getcwd() 38 | PKG_NAME = os.path.basename(SRC) 39 | 40 | SYS_NAME = platform.system() 41 | if SYS_NAME == "Windows": 42 | BIN_SCRIPTS = "Scripts" 43 | elif SYS_NAME in ["Darwin", "Linux"]: 44 | BIN_SCRIPTS = "bin" 45 | 46 | 47 | def is_venv(): 48 | """Check whether if this workspace is a virtualenv. 49 | """ 50 | dir_path = os.path.dirname(SRC) 51 | is_venv_flag = True 52 | 53 | if SYS_NAME == "Windows": 54 | executable_list = ["activate", "pip.exe", "python.exe"] 55 | elif SYS_NAME in ["Darwin", "Linux"]: 56 | executable_list = ["activate", "pip", "python"] 57 | 58 | for executable in executable_list: 59 | path = os.path.join(dir_path, BIN_SCRIPTS, executable) 60 | if not os.path.exists(path): 61 | is_venv_flag = False 62 | 63 | return is_venv_flag 64 | 65 | 66 | def find_linux_venv_py_version(): 67 | """Find python version name used in this virtualenv. 68 | 69 | For example: ``python2.7``, ``python3.4`` 70 | """ 71 | available_python_version = [ 72 | "python2.6", 73 | "python2.7", 74 | "python3.3", 75 | "python3.4", 76 | "python3.5", 77 | "python3.6", 78 | ] 79 | dir_path = os.path.dirname(SRC) 80 | for basename in os.listdir(os.path.join(dir_path, BIN_SCRIPTS)): 81 | for python_version in available_python_version: 82 | if python_version in basename: 83 | return python_version 84 | raise Exception("Can't find virtualenv python version!") 85 | 86 | 87 | def find_venv_DST(): 88 | """Find where this package should be installed to in this virtualenv. 89 | 90 | For example: ``/path-to-venv/lib/python2.7/site-packages/package-name`` 91 | """ 92 | dir_path = os.path.dirname(SRC) 93 | 94 | if SYS_NAME == "Windows": 95 | DST = os.path.join(dir_path, "Lib", "site-packages", PKG_NAME) 96 | elif SYS_NAME in ["Darwin", "Linux"]: 97 | python_version = find_linux_venv_py_version() 98 | DST = os.path.join(dir_path, "lib", python_version, "site-packages", PKG_NAME) 99 | 100 | return DST 101 | 102 | 103 | def find_DST(): 104 | """Find where this package should be installed to. 105 | """ 106 | if SYS_NAME == "Windows": 107 | return os.path.join(site.getsitepackages()[1], PKG_NAME) 108 | elif SYS_NAME in ["Darwin", "Linux"]: 109 | return os.path.join(site.getsitepackages()[0], PKG_NAME) 110 | 111 | 112 | if is_venv(): 113 | DST = find_venv_DST() 114 | else: 115 | DST = find_DST() 116 | 117 | 118 | def md5_of_file(abspath): 119 | """Md5 value of a file. 120 | """ 121 | chunk_size = 1024 * 1024 122 | m = hashlib.md5() 123 | with open(abspath, "rb") as f: 124 | while True: 125 | data = f.read(chunk_size) 126 | if not data: 127 | break 128 | m.update(data) 129 | return m.hexdigest() 130 | 131 | 132 | def check_need_install(): 133 | """Check if installed package are exactly the same to this one. 134 | By checking md5 value of all files. 135 | """ 136 | need_install_flag = False 137 | for root, _, basename_list in os.walk(SRC): 138 | if os.path.basename(root) != "__pycache__": 139 | for basename in basename_list: 140 | src = os.path.join(root, basename) 141 | dst = os.path.join(root.replace(SRC, DST), basename) 142 | if os.path.exists(dst): 143 | if md5_of_file(src) != md5_of_file(dst): 144 | return True 145 | else: 146 | return True 147 | return need_install_flag 148 | 149 | 150 | def install(): 151 | """Manual install main script. 152 | """ 153 | # check installed package 154 | print("Compare to '%s' ..." % DST) 155 | need_install_flag = check_need_install() 156 | if not need_install_flag: 157 | print(" package is up-to-date, no need to install.") 158 | return 159 | print("Difference been found, start installing ...") 160 | 161 | # remove __pycache__ folder and *.pyc file 162 | print("Remove *.pyc file ...") 163 | pyc_folder_list = list() 164 | for root, _, basename_list in os.walk(SRC): 165 | if os.path.basename(root) == "__pycache__": 166 | pyc_folder_list.append(root) 167 | 168 | for folder in pyc_folder_list: 169 | shutil.rmtree(folder) 170 | print(" all *.pyc file has been removed.") 171 | 172 | # install this package to all python version 173 | print("Uninstall %s from %s ..." % (PKG_NAME, DST)) 174 | try: 175 | shutil.rmtree(DST) 176 | print(" Successfully uninstall %s" % PKG_NAME) 177 | except Exception as e: 178 | print(" %s" % e) 179 | 180 | print("Install %s to %s ..." % (PKG_NAME, DST)) 181 | shutil.copytree(SRC, DST) 182 | print(" Complete!") 183 | 184 | 185 | if __name__ == "__main__": 186 | install() -------------------------------------------------------------------------------- /make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Command file for Sphinx documentation 4 | 5 | if "%SPHINXBUILD%" == "" ( 6 | set SPHINXBUILD=sphinx-build 7 | ) 8 | set BUILDDIR=build 9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% source 10 | set I18NSPHINXOPTS=%SPHINXOPTS% source 11 | if NOT "%PAPER%" == "" ( 12 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% 13 | set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% 14 | ) 15 | 16 | if "%1" == "" goto help 17 | 18 | if "%1" == "help" ( 19 | :help 20 | echo.Please use `make ^` where ^ is one of 21 | echo. html to make standalone HTML files 22 | echo. dirhtml to make HTML files named index.html in directories 23 | echo. singlehtml to make a single large HTML file 24 | echo. pickle to make pickle files 25 | echo. json to make JSON files 26 | echo. htmlhelp to make HTML files and a HTML help project 27 | echo. qthelp to make HTML files and a qthelp project 28 | echo. devhelp to make HTML files and a Devhelp project 29 | echo. epub to make an epub 30 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 31 | echo. text to make text files 32 | echo. man to make manual pages 33 | echo. texinfo to make Texinfo files 34 | echo. gettext to make PO message catalogs 35 | echo. changes to make an overview over all changed/added/deprecated items 36 | echo. xml to make Docutils-native XML files 37 | echo. pseudoxml to make pseudoxml-XML files for display purposes 38 | echo. linkcheck to check all external links for integrity 39 | echo. doctest to run all doctests embedded in the documentation if enabled 40 | echo. coverage to run coverage check of the documentation if enabled 41 | goto end 42 | ) 43 | 44 | if "%1" == "clean" ( 45 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 46 | del /q /s %BUILDDIR%\* 47 | goto end 48 | ) 49 | 50 | 51 | REM Check if sphinx-build is available and fallback to Python version if any 52 | %SPHINXBUILD% 2> nul 53 | if errorlevel 9009 goto sphinx_python 54 | goto sphinx_ok 55 | 56 | :sphinx_python 57 | 58 | set SPHINXBUILD=python -m sphinx.__init__ 59 | %SPHINXBUILD% 2> nul 60 | if errorlevel 9009 ( 61 | echo. 62 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 63 | echo.installed, then set the SPHINXBUILD environment variable to point 64 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 65 | echo.may add the Sphinx directory to PATH. 66 | echo. 67 | echo.If you don't have Sphinx installed, grab it from 68 | echo.http://sphinx-doc.org/ 69 | exit /b 1 70 | ) 71 | 72 | :sphinx_ok 73 | 74 | 75 | if "%1" == "html" ( 76 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 77 | if errorlevel 1 exit /b 1 78 | echo. 79 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 80 | goto end 81 | ) 82 | 83 | if "%1" == "dirhtml" ( 84 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 85 | if errorlevel 1 exit /b 1 86 | echo. 87 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 88 | goto end 89 | ) 90 | 91 | if "%1" == "singlehtml" ( 92 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 93 | if errorlevel 1 exit /b 1 94 | echo. 95 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 96 | goto end 97 | ) 98 | 99 | if "%1" == "pickle" ( 100 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 101 | if errorlevel 1 exit /b 1 102 | echo. 103 | echo.Build finished; now you can process the pickle files. 104 | goto end 105 | ) 106 | 107 | if "%1" == "json" ( 108 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 109 | if errorlevel 1 exit /b 1 110 | echo. 111 | echo.Build finished; now you can process the JSON files. 112 | goto end 113 | ) 114 | 115 | if "%1" == "htmlhelp" ( 116 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 117 | if errorlevel 1 exit /b 1 118 | echo. 119 | echo.Build finished; now you can run HTML Help Workshop with the ^ 120 | .hhp project file in %BUILDDIR%/htmlhelp. 121 | goto end 122 | ) 123 | 124 | if "%1" == "qthelp" ( 125 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 126 | if errorlevel 1 exit /b 1 127 | echo. 128 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 129 | .qhcp project file in %BUILDDIR%/qthelp, like this: 130 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\macro.qhcp 131 | echo.To view the help file: 132 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\macro.ghc 133 | goto end 134 | ) 135 | 136 | if "%1" == "devhelp" ( 137 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 138 | if errorlevel 1 exit /b 1 139 | echo. 140 | echo.Build finished. 141 | goto end 142 | ) 143 | 144 | if "%1" == "epub" ( 145 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 146 | if errorlevel 1 exit /b 1 147 | echo. 148 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 149 | goto end 150 | ) 151 | 152 | if "%1" == "latex" ( 153 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 154 | if errorlevel 1 exit /b 1 155 | echo. 156 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 157 | goto end 158 | ) 159 | 160 | if "%1" == "latexpdf" ( 161 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 162 | cd %BUILDDIR%/latex 163 | make all-pdf 164 | cd %~dp0 165 | echo. 166 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 167 | goto end 168 | ) 169 | 170 | if "%1" == "latexpdfja" ( 171 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 172 | cd %BUILDDIR%/latex 173 | make all-pdf-ja 174 | cd %~dp0 175 | echo. 176 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 177 | goto end 178 | ) 179 | 180 | if "%1" == "text" ( 181 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 182 | if errorlevel 1 exit /b 1 183 | echo. 184 | echo.Build finished. The text files are in %BUILDDIR%/text. 185 | goto end 186 | ) 187 | 188 | if "%1" == "man" ( 189 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 190 | if errorlevel 1 exit /b 1 191 | echo. 192 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 193 | goto end 194 | ) 195 | 196 | if "%1" == "texinfo" ( 197 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo 198 | if errorlevel 1 exit /b 1 199 | echo. 200 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. 201 | goto end 202 | ) 203 | 204 | if "%1" == "gettext" ( 205 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale 206 | if errorlevel 1 exit /b 1 207 | echo. 208 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale. 209 | goto end 210 | ) 211 | 212 | if "%1" == "changes" ( 213 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 214 | if errorlevel 1 exit /b 1 215 | echo. 216 | echo.The overview file is in %BUILDDIR%/changes. 217 | goto end 218 | ) 219 | 220 | if "%1" == "linkcheck" ( 221 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 222 | if errorlevel 1 exit /b 1 223 | echo. 224 | echo.Link check complete; look for any errors in the above output ^ 225 | or in %BUILDDIR%/linkcheck/output.txt. 226 | goto end 227 | ) 228 | 229 | if "%1" == "doctest" ( 230 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 231 | if errorlevel 1 exit /b 1 232 | echo. 233 | echo.Testing of doctests in the sources finished, look at the ^ 234 | results in %BUILDDIR%/doctest/output.txt. 235 | goto end 236 | ) 237 | 238 | if "%1" == "coverage" ( 239 | %SPHINXBUILD% -b coverage %ALLSPHINXOPTS% %BUILDDIR%/coverage 240 | if errorlevel 1 exit /b 1 241 | echo. 242 | echo.Testing of coverage in the sources finished, look at the ^ 243 | results in %BUILDDIR%/coverage/python.txt. 244 | goto end 245 | ) 246 | 247 | if "%1" == "xml" ( 248 | %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml 249 | if errorlevel 1 exit /b 1 250 | echo. 251 | echo.Build finished. The XML files are in %BUILDDIR%/xml. 252 | goto end 253 | ) 254 | 255 | if "%1" == "pseudoxml" ( 256 | %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml 257 | if errorlevel 1 exit /b 1 258 | echo. 259 | echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. 260 | goto end 261 | ) 262 | 263 | :end 264 | -------------------------------------------------------------------------------- /pypi-register.bat: -------------------------------------------------------------------------------- 1 | pushd "%~dp0" 2 | python3 setup.py register -r pypi -------------------------------------------------------------------------------- /pypi-upload.bat: -------------------------------------------------------------------------------- 1 | pushd "%~dp0" 2 | CHOICE /C YN /M "upload to pypi, Y to continue, N to cancle" 3 | IF ERRORLEVEL==2 goto end 4 | IF ERRORLEVEL==1 goto upload 5 | 6 | :upload 7 | python3 setup.py sdist upload -r pypi 8 | goto end 9 | 10 | :end 11 | pause -------------------------------------------------------------------------------- /recipe/might_and_magic_VI.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | 魔法门6自动化脚本。 6 | """ 7 | 8 | from macro.bot import bot 9 | 10 | #--- 以下两个方法用户魔法门6角色修改器 --- 11 | def learn_all_skill(level=60, master_level=0): 12 | """在技能编辑界面学会所有的技能。运行脚本前, 将鼠标放在第一个技能的技能等级 13 | 的数字上, 并选中所有文本。然后运行此脚本, 并在1秒内切回到修改器界面。 14 | 15 | :param level: 技能等级 16 | :param master_level: 专精等级, 0是普通, 1是专家, 2是大师 17 | """ 18 | level = str(level) 19 | bot.delay(1.0) 20 | for i in range(31): # 一共31个技能 21 | bot.type_string(level) 22 | bot.tab() 23 | bot.up(n=2) 24 | bot.down(n=master_level) 25 | bot.tab() 26 | 27 | # learn_all_skill(level=1, master_level=0) 28 | 29 | def learn_all_magic(): 30 | """在魔法全书界面学会所有的技能。运行脚本前, 用鼠标选中第一个魔法, 设置为 31 | 未习得。 32 | """ 33 | bot.delay(1.0) 34 | for i in range(9 * 11): # 一共99个技能 35 | bot.space() 36 | bot.tab() 37 | 38 | # learn_all_magic() -------------------------------------------------------------------------------- /release-history.rst: -------------------------------------------------------------------------------- 1 | Release and Version History 2 | =========================== 3 | 4 | 0.0.3 (TODO) 5 | ~~~~~~~~~~~~~~~~~~ 6 | **Features and Improvements** 7 | 8 | **Minor Improvements** 9 | 10 | **Bugfixes** 11 | 12 | **Miscellaneous** 13 | 14 | 15 | 0.0.2 (TODO) 16 | ~~~~~~~~~~~~~~~~~~ 17 | **Bugfixes** 18 | 19 | Fixed a bug that made ``bot.space()`` not working. 20 | 21 | 22 | 0.0.1 (2016-06-14) 23 | ~~~~~~~~~~~~~~~~~~ 24 | - First release -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | PyUserInput==0.1.9 2 | pyperclip==1.5.26 -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | from __future__ import print_function 5 | from setuptools import setup, find_packages 6 | from datetime import date 7 | import os 8 | 9 | #--- Define project dependent variable --- 10 | # Your package name 11 | NAME = "macro" 12 | # Your GitHub user name 13 | GITHUB_USERNAME = "MacHu-GWU" # your GitHub account name 14 | 15 | 16 | #--- Automatically generate setup parameters --- 17 | try: 18 | SHORT_DESCRIPTION = __import__(NAME).__short_description__ # GitHub Short Description 19 | except: 20 | print("'__short_description__' not found in '%s.__init__.py'!" % NAME) 21 | SHORT_DESCRIPTION = "No short description!" 22 | 23 | try: 24 | LONG_DESCRIPTION = open("README.rst", "rb").read().decode("utf-8") 25 | except: 26 | LONG_DESCRIPTION = "No long description!" 27 | 28 | VERSION = __import__(NAME).__version__ 29 | AUTHOR = "Sanhe Hu" 30 | AUTHOR_EMAIL = "husanhe@gmail.com" 31 | MAINTAINER = "Sanhe Hu" 32 | MAINTAINER_EMAIL = "husanhe@gmail.com" 33 | 34 | # Include all sub packages in package directory 35 | PACKAGES = [NAME] + ["%s.%s" % (NAME, i) for i in find_packages(NAME)] 36 | # Include everything in package directory 37 | INCLUDE_PACKAGE_DATA = True 38 | PACKAGE_DATA = { 39 | "": ["*.*"], 40 | } 41 | 42 | # The project directory name is the GitHub repository name 43 | repository_name = os.path.basename(os.getcwd()) 44 | # Project Url 45 | URL = "https://github.com/{0}/{1}".format(GITHUB_USERNAME, repository_name) 46 | # Use todays date as GitHub release tag 47 | github_release_tag = str(date.today()) 48 | # Source code download url 49 | DOWNLOAD_URL = "https://github.com/{0}/{1}/tarball/{2}".format( 50 | GITHUB_USERNAME, repository_name, github_release_tag) 51 | 52 | try: 53 | LICENSE = __import__(NAME).__license__ 54 | except: 55 | print("'__license__' not found in '%s.__init__.py'!" % NAME) 56 | LICENSE = "" 57 | 58 | PLATFORMS = ["Windows", "MacOS", "Unix"] 59 | CLASSIFIERS = [ 60 | "Development Status :: 4 - Beta", 61 | "Intended Audience :: Developers", 62 | "License :: OSI Approved :: MIT License", 63 | "Natural Language :: English", 64 | "Operating System :: Microsoft :: Windows", 65 | "Operating System :: MacOS", 66 | "Operating System :: Unix", 67 | "Programming Language :: Python", 68 | "Programming Language :: Python :: 2.7", 69 | "Programming Language :: Python :: 3.3", 70 | "Programming Language :: Python :: 3.4", 71 | "Programming Language :: Python :: 3.5", 72 | ] 73 | 74 | try: 75 | f = open("requirements.txt", "rb") 76 | REQUIRES = [i.strip() for i in f.read().decode("utf-8").split("\n")] 77 | except: 78 | print("'requirements.txt' not found!") 79 | REQUIRES = list() 80 | 81 | setup( 82 | name=NAME, 83 | description=SHORT_DESCRIPTION, 84 | long_description=LONG_DESCRIPTION, 85 | version=VERSION, 86 | author=AUTHOR, 87 | author_email=AUTHOR_EMAIL, 88 | maintainer=MAINTAINER, 89 | maintainer_email=MAINTAINER_EMAIL, 90 | packages=PACKAGES, 91 | include_package_data=INCLUDE_PACKAGE_DATA, 92 | package_data=PACKAGE_DATA, 93 | url=URL, 94 | download_url=DOWNLOAD_URL, 95 | classifiers=CLASSIFIERS, 96 | platforms=PLATFORMS, 97 | license=LICENSE, 98 | install_requires=REQUIRES, 99 | ) 100 | 101 | """ 102 | Appendix 103 | -------- 104 | :: 105 | 106 | Frequent used classifiers List = [ 107 | "Development Status :: 1 - Planning", 108 | "Development Status :: 2 - Pre-Alpha", 109 | "Development Status :: 3 - Alpha", 110 | "Development Status :: 4 - Beta", 111 | "Development Status :: 5 - Production/Stable", 112 | "Development Status :: 6 - Mature", 113 | "Development Status :: 7 - Inactive", 114 | 115 | "Intended Audience :: Customer Service", 116 | "Intended Audience :: Developers", 117 | "Intended Audience :: Education", 118 | "Intended Audience :: End Users/Desktop", 119 | "Intended Audience :: Financial and Insurance Industry", 120 | "Intended Audience :: Healthcare Industry", 121 | "Intended Audience :: Information Technology", 122 | "Intended Audience :: Legal Industry", 123 | "Intended Audience :: Manufacturing", 124 | "Intended Audience :: Other Audience", 125 | "Intended Audience :: Religion", 126 | "Intended Audience :: Science/Research", 127 | "Intended Audience :: System Administrators", 128 | "Intended Audience :: Telecommunications Industry", 129 | 130 | "License :: OSI Approved :: BSD License", 131 | "License :: OSI Approved :: MIT License", 132 | "License :: OSI Approved :: Apache Software License", 133 | "License :: OSI Approved :: GNU General Public License (GPL)", 134 | "License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)", 135 | 136 | "Natural Language :: English", 137 | "Natural Language :: Chinese (Simplified)", 138 | 139 | "Operating System :: Microsoft :: Windows", 140 | "Operating System :: MacOS", 141 | "Operating System :: Unix", 142 | 143 | "Programming Language :: Python", 144 | "Programming Language :: Python :: 2", 145 | "Programming Language :: Python :: 2.7", 146 | "Programming Language :: Python :: 2 :: Only", 147 | "Programming Language :: Python :: 3", 148 | "Programming Language :: Python :: 3.3", 149 | "Programming Language :: Python :: 3.4", 150 | "Programming Language :: Python :: 3 :: Only", 151 | ] 152 | """ -------------------------------------------------------------------------------- /source/_static/macro-logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MacHu-GWU/macro-project/dae909d2d28acbfa2be623aa2dffe988f3882d4d/source/_static/macro-logo.jpg -------------------------------------------------------------------------------- /source/about.rst: -------------------------------------------------------------------------------- 1 | .. _author: 2 | 3 | About the Author 4 | ================ 5 | :: 6 | 7 | (\ (\ 8 | ( -.-)o I am a lovely Rabbit! 9 | o_(")(") 10 | 11 | **Sanhe Hu** is a very active **Python Developer** Since 2010. Now working at `WeatherBugHome `_ as a **Data Scientist**. Research area includes **Machine Learning, Big Data Infrastructure, Business Intelligent, Open Cloud, Distribute System**. Love photography, vocal, sports, arts, game, and also the best `Python `_. 12 | 13 | - My Github: https://github.com/MacHu-GWU 14 | - My HomePage: http://www.sanhehu.org/ -------------------------------------------------------------------------------- /source/bot/content.rst: -------------------------------------------------------------------------------- 1 | Mouse and Keyboard Robot Usage Guide 2 | ==================================== 3 | First, import:: 4 | 5 | >>> from macro.bot import bot 6 | 7 | Do some mouse move:: 8 | 9 | # Double left click at (600, 600) 10 | >>> bot.left_click(600, 600, 2) 11 | 12 | Single key tap:: 13 | 14 | # Tap "a" 15 | >>> bot.tap_key("a") 16 | 17 | # Tap space 4 times 18 | >>> bot.tap_key(" ", n=4) 19 | 20 | Typing:: 21 | 22 | >>> bot.type_string("Hello World!") 23 | 24 | 25 | Highlight features 26 | ------------------ 27 | **Pre/Post delay**: 28 | 29 | In some case, you need insert a delay before or after your operation. For example, you need a buffer time in between a series of operations. Almost every methods take two option keyword ``pre_dl`` and ``post_dl`` for pre-delay and post-delay. 30 | 31 | By default, it's no delay before and after your operation. But if you want to add a default one, you can edit ``bot.dl``. This value is the default pre/post delay time if you don't define it explicitly. 32 | 33 | **Key name syntax support**: 34 | 35 | You can program Keyboard key by using it's name easily. 36 | 37 | :: 38 | 39 | >>> bot.tap_key("tab") 40 | >>> bot.tap_key("del") 41 | 42 | For list of key name, check :class:`this `. 43 | 44 | **Easy Keyboard Combination**: 45 | 46 | :: 47 | 48 | # Ctrl + C for copy 49 | >>> bot.press_and_tap("ctrl", "c") 50 | 51 | # Alt + Tab x 2 52 | >>> bot.press_and_tap("alt", "tab", n=2) -------------------------------------------------------------------------------- /source/bot/index.rst: -------------------------------------------------------------------------------- 1 | .. include:: content.rst 2 | 3 | -------------------------------------------------------------------------------- /source/conf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # 4 | # macro documentation build configuration file, created by 5 | # sphinx-quickstart on Tue Jun 14 17:54:41 2016. 6 | # 7 | # This file is execfile()d with the current directory set to its 8 | # containing dir. 9 | # 10 | # Note that not all possible configuration values are present in this 11 | # autogenerated file. 12 | # 13 | # All configuration values have a default; values that are commented out 14 | # serve to show the default. 15 | 16 | import sys 17 | import os 18 | import shlex 19 | import macro 20 | from datetime import date 21 | 22 | # If extensions (or modules to document with autodoc) are in another directory, 23 | # add these directories to sys.path here. If the directory is relative to the 24 | # documentation root, use os.path.abspath to make it absolute, like shown here. 25 | #sys.path.insert(0, os.path.abspath('.')) 26 | 27 | # -- General configuration ------------------------------------------------ 28 | 29 | # If your documentation needs a minimal Sphinx version, state it here. 30 | #needs_sphinx = '1.0' 31 | 32 | # Add any Sphinx extension module names here, as strings. They can be 33 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 34 | # ones. 35 | extensions = [ 36 | 'sphinx.ext.autodoc', 37 | 'sphinx.ext.doctest', 38 | 'sphinx.ext.intersphinx', 39 | 'sphinx.ext.todo', 40 | 'sphinx.ext.coverage', 41 | 'sphinx.ext.mathjax', 42 | 'sphinx.ext.ifconfig', 43 | 'sphinx.ext.viewcode', 44 | ] 45 | 46 | # Add any paths that contain templates here, relative to this directory. 47 | templates_path = ['_templates'] 48 | 49 | # The suffix(es) of source filenames. 50 | # You can specify multiple suffix as a list of string: 51 | # source_suffix = ['.rst', '.md'] 52 | source_suffix = '.rst' 53 | 54 | # The encoding of source files. 55 | #source_encoding = 'utf-8-sig' 56 | 57 | # The master toctree document. 58 | master_doc = 'index' 59 | 60 | # General information about the project. 61 | project = 'macro' 62 | copyright = '%s, Sanhe Hu' % date.today().year 63 | author = 'Sanhe Hu' 64 | 65 | # The version info for the project you're documenting, acts as replacement for 66 | # |version| and |release|, also used in various other places throughout the 67 | # built documents. 68 | # 69 | # The short X.Y version. 70 | version = macro.__version__ 71 | # The full version, including alpha/beta/rc tags. 72 | release = macro.__version__ 73 | 74 | # The language for content autogenerated by Sphinx. Refer to documentation 75 | # for a list of supported languages. 76 | # 77 | # This is also used if you do content translation via gettext catalogs. 78 | # Usually you set "language" from the command line for these cases. 79 | language = None 80 | 81 | # There are two options for replacing |today|: either, you set today to some 82 | # non-false value, then it is used: 83 | #today = '' 84 | # Else, today_fmt is used as the format for a strftime call. 85 | #today_fmt = '%B %d, %Y' 86 | 87 | # List of patterns, relative to source directory, that match files and 88 | # directories to ignore when looking for source files. 89 | exclude_patterns = [] 90 | 91 | # The reST default role (used for this markup: `text`) to use for all 92 | # documents. 93 | #default_role = None 94 | 95 | # If true, '()' will be appended to :func: etc. cross-reference text. 96 | #add_function_parentheses = True 97 | 98 | # If true, the current module name will be prepended to all description 99 | # unit titles (such as .. function::). 100 | #add_module_names = True 101 | 102 | # If true, sectionauthor and moduleauthor directives will be shown in the 103 | # output. They are ignored by default. 104 | #show_authors = False 105 | 106 | # The name of the Pygments (syntax highlighting) style to use. 107 | pygments_style = 'sphinx' 108 | 109 | # A list of ignored prefixes for module index sorting. 110 | #modindex_common_prefix = [] 111 | 112 | # If true, keep warnings as "system message" paragraphs in the built documents. 113 | #keep_warnings = False 114 | 115 | # If true, `todo` and `todoList` produce output, else they produce nothing. 116 | todo_include_todos = True 117 | 118 | 119 | # -- Options for HTML output ---------------------------------------------- 120 | 121 | # The theme to use for HTML and HTML Help pages. See the documentation for 122 | # a list of builtin themes. 123 | html_theme = 'alabaster' 124 | 125 | # Theme options are theme-specific and customize the look and feel of a theme 126 | # further. For a list of options available for each theme, see the 127 | # documentation. 128 | #html_theme_options = {} 129 | 130 | # Add any paths that contain custom themes here, relative to this directory. 131 | #html_theme_path = [] 132 | 133 | # The name for this set of Sphinx documents. If None, it defaults to 134 | # " v documentation". 135 | #html_title = None 136 | 137 | # A shorter title for the navigation bar. Default is the same as html_title. 138 | #html_short_title = None 139 | 140 | # The name of an image file (relative to this directory) to place at the top 141 | # of the sidebar. 142 | html_logo = "macro-logo.jpg" 143 | 144 | # The name of an image file (within the static path) to use as favicon of the 145 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 146 | # pixels large. 147 | #html_favicon = None 148 | 149 | # Add any paths that contain custom static files (such as style sheets) here, 150 | # relative to this directory. They are copied after the builtin static files, 151 | # so a file named "default.css" will overwrite the builtin "default.css". 152 | html_static_path = ['_static'] 153 | 154 | # Add any extra paths that contain custom files (such as robots.txt or 155 | # .htaccess) here, relative to this directory. These files are copied 156 | # directly to the root of the documentation. 157 | #html_extra_path = [] 158 | 159 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 160 | # using the given strftime format. 161 | #html_last_updated_fmt = '%b %d, %Y' 162 | 163 | # If true, SmartyPants will be used to convert quotes and dashes to 164 | # typographically correct entities. 165 | #html_use_smartypants = True 166 | 167 | # Custom sidebar templates, maps document names to template names. 168 | #html_sidebars = {} 169 | 170 | # Additional templates that should be rendered to pages, maps page names to 171 | # template names. 172 | #html_additional_pages = {} 173 | 174 | # If false, no module index is generated. 175 | #html_domain_indices = True 176 | 177 | # If false, no index is generated. 178 | #html_use_index = True 179 | 180 | # If true, the index is split into individual pages for each letter. 181 | #html_split_index = False 182 | 183 | # If true, links to the reST sources are added to the pages. 184 | #html_show_sourcelink = True 185 | 186 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 187 | #html_show_sphinx = True 188 | 189 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 190 | #html_show_copyright = True 191 | 192 | # If true, an OpenSearch description file will be output, and all pages will 193 | # contain a tag referring to it. The value of this option must be the 194 | # base URL from which the finished HTML is served. 195 | #html_use_opensearch = '' 196 | 197 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 198 | #html_file_suffix = None 199 | 200 | # Language to be used for generating the HTML full-text search index. 201 | # Sphinx supports the following languages: 202 | # 'da', 'de', 'en', 'es', 'fi', 'fr', 'h', 'it', 'ja' 203 | # 'nl', 'no', 'pt', 'ro', 'r', 'sv', 'tr' 204 | #html_search_language = 'en' 205 | 206 | # A dictionary with options for the search language support, empty by default. 207 | # Now only 'ja' uses this config value 208 | #html_search_options = {'type': 'default'} 209 | 210 | # The name of a javascript file (relative to the configuration directory) that 211 | # implements a search results scorer. If empty, the default will be used. 212 | #html_search_scorer = 'scorer.js' 213 | 214 | # Output file base name for HTML help builder. 215 | htmlhelp_basename = 'macrodoc' 216 | 217 | # -- Options for LaTeX output --------------------------------------------- 218 | 219 | latex_elements = { 220 | # The paper size ('letterpaper' or 'a4paper'). 221 | #'papersize': 'letterpaper', 222 | 223 | # The font size ('10pt', '11pt' or '12pt'). 224 | #'pointsize': '10pt', 225 | 226 | # Additional stuff for the LaTeX preamble. 227 | #'preamble': '', 228 | 229 | # Latex figure (float) alignment 230 | #'figure_align': 'htbp', 231 | } 232 | 233 | # Grouping the document tree into LaTeX files. List of tuples 234 | # (source start file, target name, title, 235 | # author, documentclass [howto, manual, or own class]). 236 | latex_documents = [ 237 | (master_doc, 'macro.tex', 'macro Documentation', 238 | 'Sanhe Hu', 'manual'), 239 | ] 240 | 241 | # The name of an image file (relative to this directory) to place at the top of 242 | # the title page. 243 | #latex_logo = None 244 | 245 | # For "manual" documents, if this is true, then toplevel headings are parts, 246 | # not chapters. 247 | #latex_use_parts = False 248 | 249 | # If true, show page references after internal links. 250 | #latex_show_pagerefs = False 251 | 252 | # If true, show URL addresses after external links. 253 | #latex_show_urls = False 254 | 255 | # Documents to append as an appendix to all manuals. 256 | #latex_appendices = [] 257 | 258 | # If false, no module index is generated. 259 | #latex_domain_indices = True 260 | 261 | 262 | # -- Options for manual page output --------------------------------------- 263 | 264 | # One entry per manual page. List of tuples 265 | # (source start file, name, description, authors, manual section). 266 | man_pages = [ 267 | (master_doc, 'macro', 'macro Documentation', 268 | [author], 1) 269 | ] 270 | 271 | # If true, show URL addresses after external links. 272 | #man_show_urls = False 273 | 274 | 275 | # -- Options for Texinfo output ------------------------------------------- 276 | 277 | # Grouping the document tree into Texinfo files. List of tuples 278 | # (source start file, target name, title, author, 279 | # dir menu entry, description, category) 280 | texinfo_documents = [ 281 | (master_doc, 'macro', 'macro Documentation', 282 | author, 'macro', 'One line description of project.', 283 | 'Miscellaneous'), 284 | ] 285 | 286 | # Documents to append as an appendix to all manuals. 287 | #texinfo_appendices = [] 288 | 289 | # If false, no module index is generated. 290 | #texinfo_domain_indices = True 291 | 292 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 293 | #texinfo_show_urls = 'footnote' 294 | 295 | # If true, do not generate a @detailmenu in the "Top" node's menu. 296 | #texinfo_no_detailmenu = False 297 | 298 | 299 | # -- Options for Epub output ---------------------------------------------- 300 | 301 | # Bibliographic Dublin Core info. 302 | epub_title = project 303 | epub_author = author 304 | epub_publisher = author 305 | epub_copyright = copyright 306 | 307 | # The basename for the epub file. It defaults to the project name. 308 | #epub_basename = project 309 | 310 | # The HTML theme for the epub output. Since the default themes are not optimized 311 | # for small screen space, using the same theme for HTML and epub output is 312 | # usually not wise. This defaults to 'epub', a theme designed to save visual 313 | # space. 314 | #epub_theme = 'epub' 315 | 316 | # The language of the text. It defaults to the language option 317 | # or 'en' if the language is not set. 318 | #epub_language = '' 319 | 320 | # The scheme of the identifier. Typical schemes are ISBN or URL. 321 | #epub_scheme = '' 322 | 323 | # The unique identifier of the text. This can be a ISBN number 324 | # or the project homepage. 325 | #epub_identifier = '' 326 | 327 | # A unique identification for the text. 328 | #epub_uid = '' 329 | 330 | # A tuple containing the cover image and cover page html template filenames. 331 | #epub_cover = () 332 | 333 | # A sequence of (type, uri, title) tuples for the guide element of content.opf. 334 | #epub_guide = () 335 | 336 | # HTML files that should be inserted before the pages created by sphinx. 337 | # The format is a list of tuples containing the path and title. 338 | #epub_pre_files = [] 339 | 340 | autodoc_member_order = 'bysource' 341 | 342 | # HTML files shat should be inserted after the pages created by sphinx. 343 | # The format is a list of tuples containing the path and title. 344 | #epub_post_files = [] 345 | 346 | # A list of files that should not be packed into the epub file. 347 | epub_exclude_files = ['search.html'] 348 | 349 | # The depth of the table of contents in toc.ncx. 350 | #epub_tocdepth = 3 351 | 352 | # Allow duplicate toc entries. 353 | #epub_tocdup = True 354 | 355 | # Choose between 'default' and 'includehidden'. 356 | #epub_tocscope = 'default' 357 | 358 | # Fix unsupported image types using the Pillow. 359 | #epub_fix_images = False 360 | 361 | # Scale large images. 362 | #epub_max_image_width = 0 363 | 364 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 365 | #epub_show_urls = 'inline' 366 | 367 | # If false, no index is generated. 368 | #epub_use_index = True 369 | 370 | 371 | # Example configuration for intersphinx: refer to the Python standard library. 372 | intersphinx_mapping = {'https://docs.python.org/': None} 373 | -------------------------------------------------------------------------------- /source/content.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../README.rst 2 | 3 | .. include:: about.rst 4 | 5 | Appendix 6 | -------- 7 | - :ref:`API Reference ` -------------------------------------------------------------------------------- /source/index.rst: -------------------------------------------------------------------------------- 1 | .. include:: content.rst 2 | 3 | 4 | Table of Content (目录) 5 | ----------------------- 6 | .. toctree:: 7 | :maxdepth: 1 8 | 9 | Mouse and Keyboard Robot Usage Guide 10 | -------------------------------------------------------------------------------- /source/macro/__init__.rst: -------------------------------------------------------------------------------- 1 | macro 2 | ===== 3 | 4 | .. automodule:: macro 5 | :members: 6 | 7 | sub packages and modules 8 | ------------------------ 9 | 10 | .. toctree:: 11 | :maxdepth: 1 12 | 13 | bot 14 | zzz_manual_install 15 | -------------------------------------------------------------------------------- /source/macro/bot.rst: -------------------------------------------------------------------------------- 1 | bot 2 | === 3 | 4 | .. automodule:: macro.bot 5 | :members: -------------------------------------------------------------------------------- /source/macro/dec.rst: -------------------------------------------------------------------------------- 1 | dec 2 | === 3 | 4 | .. automodule:: macro.dec 5 | :members: -------------------------------------------------------------------------------- /tests/test_bot.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | from __future__ import print_function 5 | from macro.bot import bot 6 | 7 | bot.dl = 0.5 8 | 9 | def test_press_and_tap(): 10 | bot.press_and_tap("ctrl", "c") 11 | bot.press_and_tap("alt", "tab", 5, interval=0.5) 12 | 13 | test_press_and_tap() 14 | 15 | def test_get_screen_size(): 16 | print(bot.get_screen_size()) 17 | print(bot.get_position()) 18 | 19 | test_get_screen_size() -------------------------------------------------------------------------------- /view-doc.bat: -------------------------------------------------------------------------------- 1 | pushd "%~dp0" 2 | cd build 3 | cd html 4 | index.html --------------------------------------------------------------------------------