Skip to content

python-utilities/xmouse_remote

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

XMouse Remote

Python2/3 mouse wrapper API of Xlib

Byte size of init.py Open Issues Open Pull Requests Latest commits


Table of Contents


Quick Start

Bash Variables

_module_name='xmouse_remote'
_module_https_url="https://github.com/python-utilities/${_module_name}.git"
_module_relative_path="lib/modules/${_module_name}"

Bash Submodule Commands

cd "<your-git-project-path>"

git checkout master
mkdir -vp "lib/modules"

git submodule add\
 -b master --name "${_module_name}"\
 "${_module_https_url}" "${_module_relative_path}"

Your ReadMe File

Suggested additions for your ReadMe.md file so everyone has a good time with submodules

Install Python dependencies


    pip3 install --user Xlib


Clone with the following to avoid incomplete downloads


    git clone --recurse-submodules <url-for-your-project>


Update/upgrade submodules via


    git submodule update --init --merge --recursive

Utilize XMouse Remote

As an import

#!/usr/bin/env python3


from lib.modules.xmouse_remote import XMouse_Remote


mouse = XMouse_Remote(display = ':0', button_ids = {
    'button_left': 1,
    'button_middle': 2,
    'button_right': 3,
    'scroll_up': 4,
    'scroll_down': 5,
    'scroll_left': 6,
    'scroll_right': 7
})


mouse.move_relative(x = 5)
print("XMouse_Remote location -> {}".format(mouse.location))

mouse.drag_relative(y=-55)
print("XMouse_Remote location -> {}".format(mouse.location))

As a base class

#!/usr/bin/env python3


import time

from lib.modules.xmouse_remote import XMouse_Remote


class XMouse_Custom_Remote(XMouse_Remote):
    """
    XMouse_Custom_Remote extends XMouse_Remote with multi button support
    """

    def __init__(self, display = None, button_ids = None):
        super(XMouse_Custom_Remote, self).__init__(display = display, button_ids = button_ids)
        self._target_ids = [1]

    def multi_button_press(self, ids = [1], names = None, sync = True):
        """
        Press list of button IDs or names

        - `ids` list of button IDs to press
        - `names` list of button names to press
        """
        self._target_ids = ids
        if names is not None:
            self._target_ids = [self.button_ids.get(button_name, 1) for button_name in names]

        for _target_id in self._target_ids:
            self.button_press(detail = _target_id, sync = sync)

    def multi_button_release(self, ids = [1], names = None, sync = True):
        """
        Releases list of button IDs or names

        - `ids` list of button IDs to release
        - `names` list of button names to release
        """
        self._target_ids = ids
        if names is not None:
            self._target_ids = [self.button_ids.get(button_name, 1) for button_name in names]

        for _target_id in self._target_ids:
            self.button_release(detail = _target_id, sync = sync)

    def multi_drag_relative(self, x = 0, y = 0, ids = [1], names = None, sync = True, delays = {0: 0.01, 1: 0.01}):
        """
        Starting at `self.location`, moves to relative coordinates while pressing defined button IDs or names

        - `ids` list of button IDs to press while moving
        - `names` list of button names to press while moving
        """
        self.multi_button_press(ids = ids, names = names, sync = sync)

        if delays.get(0, 0) > 0:
            time.sleep(delays[0])

        self.move_relative(x = x, y = y, sync = sync)

        if delays.get(1, 0) > 0:
            time.sleep(delays[1])

        self.multi_button_release(ids = ids, names = names, sync = sync)

        return self.location

Commit and Push

git add .gitmodules
git add lib/modules/xmouse_remote


## Add any changed files too


git commit -F- <<'EOF'
:heavy_plus_sign: Adds `python-utilities/xmouse_remote#1` submodule

# ... anything else noteworthy
EOF


git push origin master

🎉 Excellent 🎉 your repository is now ready to begin unitizing code from this project!


Notes

Check out the gh-pages branch for command-line examples and further documentation. Pull Requests are welcome for fixing bugs and/or adding features.


Attribution


License

Legal bits of Open Source software

XMouse Remote ReadMe documenting how things like this could be utilized
Copyright (C) 2019  S0AndS0

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation; version 3 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.