lqg 2 years ago
parent
commit
4e57a49659

+ 14 - 0
.github/ISSUE_TEMPLATE.md

@@ -0,0 +1,14 @@
+**System information**
+
+- App version: 
+- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): 
+- Python version: 
+
+**Describe the expected behavior**
+
+
+
+**Other info / logs**    
+Include any logs or source code that would be helpful to diagnose the problem. 
+If including tracebacks, please include the full traceback. Large logs and files should be attached.
+

+ 15 - 0
.github/PULL_REQUEST_TEMPLATE.md

@@ -0,0 +1,15 @@
+This pull request closes #issue_number_here.
+
+**- What I did**
+
+
+
+**- How I did it**
+
+
+
+**- How to verify it**
+<!-- 
+You need a good justification for not 
+including tests for the new feature you added. 
+-->

+ 61 - 0
.github/workflows/python.yml

@@ -0,0 +1,61 @@
+name: auto CI
+
+on:
+  push:
+    branches: [ master ]
+  pull_request:
+    branches: [ master ]
+
+jobs:
+  build:
+    strategy:
+      matrix:
+        os: [ubuntu-latest]
+        include:
+        - os: ubuntu-latest
+          path: ~/.cache/pip
+        - os: macos-latest
+          path: ~/Library/Caches/pip
+        - os: windows-latest
+          path: ~\AppData\Local\pip\Cache
+    runs-on: ubuntu-latest
+
+    steps:
+      - uses: actions/checkout@v2
+        
+      - name: Set up Python 3.8
+        id: setup-python
+        uses: actions/setup-python@v2
+        with:
+          python-version: 3.8
+
+      - uses: actions/cache@v2
+        with:
+          path: ${{ matrix.path }}
+          key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
+          restore-keys: |
+            ${{ runner.os }}-pip-
+
+      - uses: actions/cache@v2
+        with:
+          path: ~/.local/share/virtualenvs
+          key: ${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-pipenv-${{ hashFiles('Pipfile.lock') }}
+        
+      - name: Install dependencies
+        run: |
+          python -m pip install --upgrade pip
+          if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
+
+      - name: Publish distribution 📦 to Test PyPI
+        uses: pypa/gh-action-pypi-publish@master
+        with:
+          user: __token__
+          password: ${{ secrets.test_pypi_password }}
+          repository_url: https://test.pypi.org/legacy/
+
+      - name: Publish distribution 📦 to PyPI
+        if: startsWith(github.event.ref, 'refs/tags')
+        uses: pypa/gh-action-pypi-publish@master
+        with:
+          user: __token__
+          password: ${{ secrets.pypi_password }}

+ 4 - 0
README.ZH.md

@@ -0,0 +1,4 @@
+# ShareMouse
+
+python 多设备鼠标键盘共享工具
+

+ 26 - 1
README.md

@@ -1,3 +1,28 @@
 # ShareMouse
 
-python 多设备鼠标键盘共享工具
+[![Version](https://img.shields.io/badge/version-v1.1.0-brightgreen)](https://git.yoqi.me/lyq/ShareMouse)
+[![.NET](https://img.shields.io/badge/python-v3.8-brightgreen?style=plastic)](https://git.yoqi.me/lyq/ShareMouse)
+
+[English](./README.md) | [中文](./README.zh-CN.md)
+
+python 多设备鼠标键盘共享工具
+
+![](https://git.yoqi.me/attachments/e92bbdd3-08bf-4b75-8526-a5bd68f75da0)
+
+
+## Contributing
+
+* Submit [bugs and feature requests](https://git.yoqi.me/lyq/Saying/issues), and help us verify as they are checked in
+* Review [source code changes](https://git.yoqi.me/lyq/Saying/pulls) 
+* Leave a message to us: liuyuqi.gov@msn.cn
+
+source build:
+```
+./gradlew assembleDebug
+```
+
+## License
+
+如果您在你的项目中使用我们的代码,请保留 License 声明,谢谢
+
+Licensed under the [Apache 2.0](LICENSE) © [liuyuqi.gov@msn.cn](https://github.com/jianboy)

+ 7 - 0
bin/sharemouse

@@ -0,0 +1,7 @@
+#!/bin/bash
+# @Contact :   liuyuqi.gov@msn.cn
+# @Time    :   2022/11/05 14:40:50
+# @License :   (C)Copyright 2022 liuyuqi.
+# @Desc    :   enter point
+###############################################################################
+python ../main.py

+ 6 - 0
conf/config.json

@@ -0,0 +1,6 @@
+{
+    "username": "",
+    "token": "",
+    "pwd": "",
+    "port": ""
+}

+ 14 - 0
main.py

@@ -0,0 +1,14 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+'''
+@Contact :   liuyuqi.gov@msn.cn
+@Time    :   2022/10/30 19:14:19
+@License :   Copyright © 2017-2022 liuyuqi. All Rights Reserved.
+@Desc    :   enter point
+'''
+
+from sharemouse import main
+
+
+if __name__=='__main__':
+    main()

+ 0 - 0
requirements.txt


+ 12 - 0
sharemouse/__init__.py

@@ -0,0 +1,12 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+'''
+@Contact :   liuyuqi.gov@msn.cn
+@Time    :   2022/11/05 14:33:18
+@License :   Copyright © 2017-2022 liuyuqi. All Rights Reserved.
+@Desc    :   
+'''
+from sharemouse.sharemouse import ShareMouse
+
+def main():
+    ShareMouse().run()

+ 28 - 0
sharemouse/client.py

@@ -0,0 +1,28 @@
+from email import header
+
+
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+'''
+@Contact :   liuyuqi.gov@msn.cn
+@Time    :   2022/10/30 19:48:21
+@License :   Copyright © 2017-2022 liuyuqi. All Rights Reserved.
+@Desc    :   
+'''
+
+class Client(object):
+    '''客户端'''
+    
+    def __init__(self):
+        pass
+
+    def connect(self):
+        '''连接server'''
+        pass
+
+    def search(self):
+        '''搜索本地 server'''
+        pass
+
+if __name__ == "__main__":
+    pass

+ 158 - 0
sharemouse/keymap.py

@@ -0,0 +1,158 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+'''
+@Contact :   liuyuqi.gov@msn.cn
+@Time    :   2022/10/30 19:17:40
+@License :   Copyright © 2017-2022 liuyuqi. All Rights Reserved.
+@Desc    :   
+'''
+# https://pyautogui.readthedocs.io/en/latest/keyboard.html
+# https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes?redirectedfrom=MSDN
+
+# ['\t', '\n', '\r', ' ', '!', '"', '#', '$', '%', '&', "'", '(',
+# ')', '*', '+', ',', '-', '.', '/',':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`','{', '|', '}', '~',
+# 'accept', 'add',  'altleft', 'altright', '',
+# 'convert', 'delete',
+# escape', # , 'fn'
+# 'modechange'
+# 'nonconvert','win''yen',
+# 'command', 'option'
+
+KEYMAP = {
+    0x09: 'tab',
+    0x0D: 'enter',
+    0x41: 'a',
+    0x42: 'b',
+    0x43: 'c',
+    0x44: 'd',
+    0x45: 'e',
+    0x46: 'f',
+    0x47: 'g',
+    0x48: 'h',
+    0x49: 'i',
+    0x4A: 'j',
+    0x4B: 'k',
+    0x4C: 'l',
+    0x4D: 'm',
+    0x4E: 'n',
+    0x4F: 'o',
+    0x50: 'p',
+    0x51: 'q',
+    0x52: 'r',
+    0x53: 's',
+    0x54: 't',
+    0x55: 'u',
+    0x56: 'v',
+    0x57: 'w',
+    0x58: 'x',
+    0x59: 'y',
+    0x5A: 'z',
+    0x30: '0',
+    0x31: '1',
+    0x32: '2',
+    0x33: '3',
+    0x34: '4',
+    0x35: '5',
+    0x36: '6',
+    0x37: '7',
+    0x38: '8',
+    0x39: '9',
+    0x0C: 'clear',
+    0x08: 'backspace',
+    0x10: 'shift',
+    # 0x11: 'ctrl',
+    0x12: 'alt',
+    0x13: 'pause',
+    0x14: 'capslock',
+    0x15: 'hangul',
+    0x17: 'junja',
+    0x18: 'final',
+    0x19: 'kanji',
+    0x1B: 'esc',
+    0x20: 'space',
+    0x21: 'pageup',
+    0x22: 'pagedown',
+    0x23: 'end',
+    0x24: 'home',
+    0x25: 'left',
+    0x26: 'up',
+    0x27: 'right',
+    0x28: 'down',
+    0x29: 'select',
+    0x2A: 'print',
+    0x2B: 'execute',
+    0x2C: 'printscreen',
+    0x2D: 'insert',
+    0x2E: 'del',
+    0x2F: 'help',
+    0x5B: 'winleft',
+    0x5C: 'winright',
+    0x5D: 'apps',
+    0x5F: 'sleep',
+    0x60: 'num0',
+    0x61: 'num1',
+    0x62: 'num2',
+    0x63: 'num3',
+    0x64: 'num4',
+    0x65: 'num5',
+    0x66: 'num6',
+    0x67: 'num7',
+    0x68: 'num8',
+    0x69: 'num9',
+    0x6A: 'multiply',
+    0x6B: 'add',
+    0x6C: 'separator',
+    0x6D: 'subtract',
+    0x6E: 'decimal',
+    0x6F: 'divide',
+    0x70: 'f1',
+    0x71: 'f2',
+    0x72: 'f3',
+    0x73: 'f4',
+    0x74: 'f5',
+    0x75: 'f6',
+    0x76: 'f7',
+    0x77: 'f8',
+    # 0x78: 'f9', # used for Pausing execution
+    0x79: 'f10',
+    0x7A: 'f11',
+    0x7B: 'f12',
+    0x7C: 'f13',
+    0x7D: 'f14',
+    0x7E: 'f15',
+    0x7F: 'f16',
+    0x80: 'f17',
+    0x81: 'f18',
+    0x82: 'f19',
+    0x83: 'f20',
+    0x84: 'f21',
+    0x85: 'f22',
+    0x86: 'f23',
+    0x87: 'f24',
+    0x90: 'numlock',
+    0x91: 'scrolllock',
+    0xA0: 'shiftleft',
+    0xA1: 'shiftright',
+    0xA2: 'ctrlleft',
+    0xA3: 'ctrlright',
+    0xA4: 'optionleft',
+    0xA5: 'optionright',
+    0xA6: 'browserback',
+    0xA7: 'browserforward',
+    0xA8: 'browserrefresh',
+    0xA9: 'browserstop',
+    0xAA: 'browsersearch',
+    0xAB: 'browserfavorites',
+    0xAC: 'browserhome',
+    0xAD: 'volumemute',
+    0xAE: 'volumedown',
+    0xAF: 'volumeup',
+    0xB0: 'nexttrack',
+    0xB1: 'prevtrack',
+    0xB2: 'stop',
+    0xB3: 'playpause',
+    0xB4: 'launchmail',
+    0xB5: 'launchmediaselect',
+    0xB6: 'launchapp1',
+    0xB7: 'launchapp2'
+}

+ 111 - 0
sharemouse/server.py

@@ -0,0 +1,111 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+'''
+@Contact :   liuyuqi.gov@msn.cn
+@Time    :   2022/10/30 19:14:43
+@License :   Copyright © 2017-2022 liuyuqi. All Rights Reserved.
+@Desc    :   
+'''
+from ctypes import windll, Structure, c_long, byref
+import socket
+import threading
+import time
+from keymap import KEYMAP
+
+class Mouse(Structure):
+    '''鼠标光标的坐标'''
+    _fields_ = [("x", c_long), ("y", c_long)]
+
+class Server(object):
+    
+    def __init__(self, port):
+        server = socket.socket()
+        server.bind(('0.0.0.0', port))
+        server.listen(5)
+        client = None
+        # client, addr = server.accept()
+        ENABLE = True
+
+        PREV_X, PREV_Y = -1, -1
+        PREV_MOUSE_LEFT = windll.user32.GetKeyState(0x01) & 0x8000
+        PREV_MOUSE_RIGHT = windll.user32.GetKeyState(0x02) & 0x8000
+
+
+    def start(self):
+        '''start server'''
+        global server
+        global client
+        global PREV_X
+        global PREV_Y
+        global PREV_MOUSE_LEFT
+        global PREV_MOUSE_RIGHT
+        global ENABLE
+
+        while True:
+            try:
+                if Server.getKeyDown(0x78):
+                    ENABLE = not ENABLE
+                    time.sleep(1)
+
+                if not ENABLE:
+                    continue
+
+                mouse_left = windll.user32.GetKeyState(0x01)
+                mouse_left = mouse_left & 0x8000
+                mouse_right = windll.user32.GetKeyState(0x02)
+                mouse_right = mouse_right & 0x8000
+                x, y = Server.getMousePos()
+                
+                for keycode, val in KEYMAP.items():
+                    if Server.getKeyDown(keycode):
+                        print(val)
+
+                if mouse_left != PREV_MOUSE_LEFT:
+                    PREV_MOUSE_LEFT = mouse_left
+                    if mouse_left != 0:
+                        #  Left Pressed
+                        print('LP')
+                    else:
+                        # Left Released
+                        print('LR')
+
+                if mouse_right != PREV_MOUSE_RIGHT:
+                    PREV_MOUSE_RIGHT = mouse_right
+                    if mouse_right != 0:
+                        # Right Pressed
+                        print('RP')
+                    else:
+                        # Right Pressed
+                        print('RR')
+                if x != PREV_X or y != PREV_Y:
+                    PREV_X, PREV_Y = x, y
+                    print(x, y)
+
+                pass
+            except:
+                pass
+            time.sleep(0.025)
+
+    def stop(self):
+        '''stop server'''
+        self.server.close()
+    
+    @staticmethod
+    def getKeyDown(keycode):
+        '''按键是否按下'''
+        state = windll.user32.GetKeyState(keycode)
+        if (state != 0) and (state != 1):
+            return True
+        return False
+
+    @staticmethod
+    def getMousePos():
+        ''''''
+        pt = Mouse()
+        windll.user32.GetCursorPos(byref(pt))
+        return (pt.x, pt.y)
+
+if __name__ == "__main__":
+    th = threading.Thread(target=Server().start())
+    th.start()
+    th.join()

+ 58 - 0
sharemouse/sharemouse.py

@@ -0,0 +1,58 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+'''
+@Contact :   liuyuqi.gov@msn.cn
+@Time    :   2022/10/30 19:18:53
+@License :   Copyright © 2017-2022 liuyuqi. All Rights Reserved.
+@Desc    :   
+
+实现逻辑: 
+pc1: 启动sharemouse, 启动server,启动client去search是否有server
+pc2: 启动sharemouse,同理,成功发现server1,
+
+
+
+'''
+import os
+import sys
+import re
+import argparse
+from turtle import st
+from sharemouse.server import Server
+from sharemouse.client import Client
+import logging as log
+
+
+class ShareMouse(object):
+
+    def __init__(self):
+        super().__init__()
+        self.parser = argparse.ArgumentParser(
+            description="config for sharemouse")
+        self.parser.add_argument(
+            "--port", type=str, default="6555", help="server port")
+        self.parser.add_argument(
+            "--username", type=str, default="", help="register and login your account.")
+        self.parser.add_argument(
+            "--pwd", type=str, default=None, help="The password of connecting to server.")
+        self.parser.add_argument("--token", type=str, default="", help="token")
+
+    def run(self):
+        # start server
+        server = Server(port=self.parser.get_default("port"))
+        server.start()
+        log.info("-----------start-------")
+        # start client and search server
+        client = Client()
+        client.connect()
+
+    def stop(self):
+        pass
+
+    def syncAction(self):
+        '''同步操作,鼠标移动,点击,键盘按键'''
+        pass
+
+
+if __name__ == "__main__":
+    ShareMouse().run()

+ 0 - 0
sharemouse/utils/__init__.py