Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
# Android Headset Media Controls for Windows
Python script that hacks in support for Android headset media control for Windows.
# Android Headset Media Controls for Windows and Linux
Python script that hacks in support for Android headset media control for Windows and Linux

For more details on how this works, see the associated [blog post](http://www.roligheten.no/blog/programming/2018/07/02/media-controls-windows.html)

## Installation

### Dependencies

#### On Windows
Regardless of the platform the following is required
1. Python 3 or 2.7 (untested) installed on the system.
2. The packages pywin32 and sounddevice, installable via `pip install pywin32 sounddevice`.
#### On Linux
##### Note: This only works on X11, No wayland Support as of now
1. Install python3 via `sudo apt install python3`
2. install packages sounddevice and numpy `pip3 install numpy sounddevice`
3. install xdotool (emulates key presses) `sudo apt install xdotool`
4. Install pypy, found to give performence improvements; recommended but not required, you can use the regular python interpreter: `sudo apt install pypy3`
if run via pypy, install requirements using `pypy3 -m pip install numpy sounddevice`

### Running and Installing

### Windows
1. Download a copy of this repository from [here](https://github.com/Catuna/AndroidMediaControlsWindows/archive/master.zip)
Expand All @@ -31,5 +44,16 @@ Regardless of the platform the following is required

7. Restart your computer. At this point you should find 'pythonw.exe' running in the task mananger under 'Background Processes' and the program should function.

### Linux and Mac
Sorry, the script currently only works for Windows at the moment, feel free to contribute code for other platforms if you have the time.
### Linux

1. Clone the repo via `git clone <url>` or download and extract the zip as listed in the first step of the windows install
2. Place it somewhere safe, maybe in the documents folder
3. cd into the directory
4. start the script via `python3 run.py` or `pypy3 run.py`, test if it works if you want to
5. test if it works
6. then add it to startup apps, as of Pop!_OS 21.04, you can do this via the startup apps application

### Mac
Not yet supported


18 changes: 14 additions & 4 deletions media_controls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import win32api
import win32con
import platform

OS = platform.system()

if OS == "Linux":
import os
elif OS == "Windows":
import win32api
import win32con
VK_MEDIA_PLAY_PAUSE = 0xB3

VK_MEDIA_PLAY_PAUSE = 0xB3

def toggle_play():
win32api.keybd_event(VK_MEDIA_PLAY_PAUSE, 0, 0, 0)
if OS == "Linux":
os.system('xdotool key XF86AudioPlay')
elif OS == "Windows":
win32api.keybd_event(VK_MEDIA_PLAY_PAUSE, 0, 0, 0)