From cc40a422e6142f67326e4295993b8f1bd30cbe27 Mon Sep 17 00:00:00 2001 From: cheykrym Date: Thu, 7 Aug 2025 05:02:08 +0300 Subject: [PATCH] init --- .gitignore | 131 ++++++++++++++++++++++++++++++++++++++++++++ README.md | 33 +++++++++++ magic_keyboard.py | 48 ++++++++++++++++ magic_keyboard.spec | 38 +++++++++++++ requirements.txt | 2 + 5 files changed, 252 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 magic_keyboard.py create mode 100644 magic_keyboard.spec create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a78e733 --- /dev/null +++ b/.gitignore @@ -0,0 +1,131 @@ +# +config/cert/ +test_modules/ +config/SSL/fullchain.pem +config/SSL/privkey.pem +logs/ +SECRET_KEY.key + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..5d39551 --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +# magic_keyboard_player + +--- + +## πŸ’» ВрСбования + +- Python **3.13.1** +- Windows (рСкомСндуСтся для `.exe` сборки) +- УстановлСнныС зависимости (`requirements.txt`) + +--- + +## πŸ› οΈ Π Π΅ΠΆΠΈΠΌ Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ + +```bash +# Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ Π²ΠΈΡ€Ρ‚ΡƒΠ°Π»ΡŒΠ½ΠΎΠ³ΠΎ окруТСния +python -m venv env + +# Установка зависимостСй +.\env\Scripts\pip3.13.exe install -r .\requirements.txt + +# Запуск +.\env\Scripts\python.exe magic_keyboard.py +``` + +## πŸ“¦ Π‘Π±ΠΎΡ€ΠΊΠ° .EXE +```bash +# Π‘Π±ΠΎΡ€ΠΊΠ° hide +.\env\Scripts\pyinstaller --noconfirm --onefile --windowed magic_keyboard.py + +# Π‘Π±ΠΎΡ€ΠΊΠ° console +.\.venv\Scripts\pyinstaller --noconfirm --onefile magic_keyboard.py +``` diff --git a/magic_keyboard.py b/magic_keyboard.py new file mode 100644 index 0000000..fabcd1c --- /dev/null +++ b/magic_keyboard.py @@ -0,0 +1,48 @@ +import keyboard +import time +import ctypes + +DEBUG = False + +# Π€ΡƒΠ½ΠΊΡ†ΠΈΠΈ для управлСния ΠΌΡƒΠ»ΡŒΡ‚ΠΈΠΌΠ΅Π΄ΠΈΠ° +def play_pause(): + if DEBUG: print("[Π”Π•Π™Π‘Π’Π’Π˜Π•] ВоспроизвСдСниС/ΠŸΠ°ΡƒΠ·Π°") + send_vk_code(0xB3) # VK_MEDIA_PLAY_PAUSE + +def next_track(): + if DEBUG: print("[Π”Π•Π™Π‘Π’Π’Π˜Π•] Π‘Π»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠΉ Ρ‚Ρ€Π΅ΠΊ") + send_vk_code(0xB0) # VK_MEDIA_NEXT_TRACK + +def prev_track(): + if DEBUG: print("[Π”Π•Π™Π‘Π’Π’Π˜Π•] ΠŸΡ€Π΅Π΄Ρ‹Π΄ΡƒΡ‰ΠΈΠΉ Ρ‚Ρ€Π΅ΠΊ") + send_vk_code(0xB1) # VK_MEDIA_PREV_TRACK + +# ΠžΡ‚ΠΏΡ€Π°Π²ΠΊΠ° Π²ΠΈΡ€Ρ‚ΡƒΠ°Π»ΡŒΠ½ΠΎΠ³ΠΎ ΠΊΠΎΠ΄Π° клавиши Π² Windows +def send_vk_code(code): + ctypes.windll.user32.keybd_event(code, 0, 0, 0) # key down + time.sleep(0.15) + ctypes.windll.user32.keybd_event(code, 0, 2, 0) # key up + +# ΠŸΡ€ΠΈΠ²ΡΠ·Ρ‹Π²Π°Π΅ΠΌ горячиС клавиши +# keyboard.add_hotkey('f7', prev_track) +# keyboard.add_hotkey('f8', play_pause) +# keyboard.add_hotkey('f9', next_track) + +keyboard.add_hotkey('right windows+f7', prev_track) +keyboard.add_hotkey('right windows+f8', play_pause) +keyboard.add_hotkey('right windows+f9', next_track) + +# ΠžΠ±Ρ€Π°Π±ΠΎΡ‚Ρ‡ΠΈΠΊ Π½Π°ΠΆΠ°Ρ‚ΠΈΠΉ клавиш (для ΠΎΡ‚Π»Π°Π΄ΠΊΠΈ) +def on_key(event): + print(f"[ΠΠΠ–ΠΠ’Πž] {event.name}") + +if DEBUG: keyboard.on_press(on_key) + +print("Π‘ΠΊΡ€ΠΈΠΏΡ‚ Π·Π°ΠΏΡƒΡ‰Π΅Π½. НаТмитС F7/F8/F9 для управлСния ΠΌΡƒΠ·Ρ‹ΠΊΠΎΠΉ. Ctrl+C β€” Π²Ρ‹Ρ…ΠΎΠ΄.") + +# БСсконСчный Ρ†ΠΈΠΊΠ» +try: + while True: + time.sleep(1) +except KeyboardInterrupt: + print("Π‘ΠΊΡ€ΠΈΠΏΡ‚ Π·Π°Π²Π΅Ρ€ΡˆΡ‘Π½.") diff --git a/magic_keyboard.spec b/magic_keyboard.spec new file mode 100644 index 0000000..c4bb812 --- /dev/null +++ b/magic_keyboard.spec @@ -0,0 +1,38 @@ +# -*- mode: python ; coding: utf-8 -*- + + +a = Analysis( + ['magic_keyboard.py'], + pathex=[], + binaries=[], + datas=[], + hiddenimports=[], + hookspath=[], + hooksconfig={}, + runtime_hooks=[], + excludes=[], + noarchive=False, + optimize=0, +) +pyz = PYZ(a.pure) + +exe = EXE( + pyz, + a.scripts, + a.binaries, + a.datas, + [], + name='magic_keyboard', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + upx_exclude=[], + runtime_tmpdir=None, + console=True, + disable_windowed_traceback=False, + argv_emulation=False, + target_arch=None, + codesign_identity=None, + entitlements_file=None, +) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..c3a5c16 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +keyboard==0.13.5 +pyinstaller==6.12.0