ds4-mapper 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ds4_mapper-0.1.0/LICENSE +21 -0
- ds4_mapper-0.1.0/PKG-INFO +167 -0
- ds4_mapper-0.1.0/README.md +135 -0
- ds4_mapper-0.1.0/ds4_mapper.egg-info/PKG-INFO +167 -0
- ds4_mapper-0.1.0/ds4_mapper.egg-info/SOURCES.txt +19 -0
- ds4_mapper-0.1.0/ds4_mapper.egg-info/dependency_links.txt +1 -0
- ds4_mapper-0.1.0/ds4_mapper.egg-info/entry_points.txt +2 -0
- ds4_mapper-0.1.0/ds4_mapper.egg-info/requires.txt +8 -0
- ds4_mapper-0.1.0/ds4_mapper.egg-info/top_level.txt +1 -0
- ds4_mapper-0.1.0/ds4mapper/__init__.py +0 -0
- ds4_mapper-0.1.0/ds4mapper/__main__.py +84 -0
- ds4_mapper-0.1.0/ds4mapper/cli.py +794 -0
- ds4_mapper-0.1.0/ds4mapper/keys.py +23 -0
- ds4_mapper-0.1.0/ds4mapper/mapper.py +143 -0
- ds4_mapper-0.1.0/ds4mapper/profiles/default.toml +26 -0
- ds4_mapper-0.1.0/ds4mapper/profiles.py +76 -0
- ds4_mapper-0.1.0/pyproject.toml +60 -0
- ds4_mapper-0.1.0/setup.cfg +4 -0
- ds4_mapper-0.1.0/tests/test_keys.py +66 -0
- ds4_mapper-0.1.0/tests/test_mapper.py +122 -0
- ds4_mapper-0.1.0/tests/test_profiles.py +155 -0
ds4_mapper-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Jared Mahan
|
|
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.
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ds4-mapper
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Map a DualShock 4 controller to keyboard inputs with a live TUI
|
|
5
|
+
Author: Jared Mahan
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/jaredmahan/ds4-mapper
|
|
8
|
+
Project-URL: Repository, https://github.com/jaredmahan/ds4-mapper
|
|
9
|
+
Project-URL: Issues, https://github.com/jaredmahan/ds4-mapper/issues
|
|
10
|
+
Keywords: ds4,dualshock4,controller,keyboard,mapping,gamepad,pygame
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
14
|
+
Classifier: Operating System :: MacOS
|
|
15
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Games/Entertainment
|
|
20
|
+
Classifier: Topic :: Utilities
|
|
21
|
+
Requires-Python: >=3.11
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: pygame-ce
|
|
25
|
+
Requires-Dist: pynput
|
|
26
|
+
Requires-Dist: rich
|
|
27
|
+
Requires-Dist: textual
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: pytest; extra == "dev"
|
|
30
|
+
Requires-Dist: ruff; extra == "dev"
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
|
|
33
|
+
# DS4 Mapper
|
|
34
|
+
|
|
35
|
+
Maps a DualShock 4 controller to keyboard inputs system-wide, so you can play browser games with a controller. Profiles are hot-swappable at runtime without restarting.
|
|
36
|
+
|
|
37
|
+
## Requirements
|
|
38
|
+
|
|
39
|
+
- Python 3.11+
|
|
40
|
+
- A DualShock 4 connected via Bluetooth
|
|
41
|
+
|
|
42
|
+
**macOS:** Grant Accessibility permission to your terminal in **System Settings → Privacy & Security → Accessibility** (required for keyboard injection).
|
|
43
|
+
|
|
44
|
+
## Install
|
|
45
|
+
|
|
46
|
+
From PyPI:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pip install ds4-mapper
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Or from source (development mode):
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
git clone https://github.com/jaredmahan/ds4-mapper.git
|
|
56
|
+
cd ds4-mapper
|
|
57
|
+
pip install -e ".[dev]"
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Usage
|
|
61
|
+
|
|
62
|
+
Connect your DS4 via Bluetooth, then run:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
ds4-mapper
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Or without installing:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
python -m ds4mapper
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Options
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
--profile NAME Profile to load on startup (default: default)
|
|
78
|
+
--discover Print raw button/axis indices — useful for building new profiles
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Discover Mode
|
|
82
|
+
|
|
83
|
+
If a button isn't registering, use discover mode to see the raw event index:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
ds4-mapper --discover
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## CLI Commands
|
|
90
|
+
|
|
91
|
+
Once the mapper is running, type commands at the `>` prompt:
|
|
92
|
+
|
|
93
|
+
| Command | Effect |
|
|
94
|
+
|---------|--------|
|
|
95
|
+
| `list` | Show available profiles |
|
|
96
|
+
| `switch <name>` | Load a profile (Tab-completes) |
|
|
97
|
+
| `current` | Show the active profile name |
|
|
98
|
+
| `reload` | Reload the current profile from disk |
|
|
99
|
+
| `view [<name>]` | Show button/axis/trigger mappings for a profile |
|
|
100
|
+
| `edit [<name>]` | Open the profile editor for an existing profile |
|
|
101
|
+
| `new <name>` | Create a new profile in the editor |
|
|
102
|
+
| `help` | Show command list |
|
|
103
|
+
| `quit` / `exit` | Stop |
|
|
104
|
+
|
|
105
|
+
## Profile Editor
|
|
106
|
+
|
|
107
|
+
`edit` and `new` open an interactive editor screen where you can map controller inputs to keyboard keys:
|
|
108
|
+
|
|
109
|
+
1. **Press a DS4 button, stick, or trigger** — the editor enters *waiting* mode and prompts for a key.
|
|
110
|
+
2. **Press the keyboard key** you want it mapped to — the mapping is recorded.
|
|
111
|
+
3. Repeat for each input you want to map.
|
|
112
|
+
|
|
113
|
+
You can also type commands in the editor's input field:
|
|
114
|
+
|
|
115
|
+
| Command | Effect |
|
|
116
|
+
|---------|--------|
|
|
117
|
+
| `save [stem]` | Save to disk (optional custom filename) |
|
|
118
|
+
| `delete <input>` | Remove a mapping (e.g. `delete Cross`) |
|
|
119
|
+
| `name <text>` | Set the profile display name |
|
|
120
|
+
| `desc <text>` | Set the profile description |
|
|
121
|
+
| `cancel` | Discard changes and return to the main screen |
|
|
122
|
+
|
|
123
|
+
Keyboard injection is suspended while the editor is open so controller inputs don't fire game actions.
|
|
124
|
+
|
|
125
|
+
## Profiles
|
|
126
|
+
|
|
127
|
+
Profiles live in `ds4mapper/profiles/`. Each is a TOML file:
|
|
128
|
+
|
|
129
|
+
```toml
|
|
130
|
+
name = "default"
|
|
131
|
+
description = "Standard browser game layout"
|
|
132
|
+
|
|
133
|
+
[buttons]
|
|
134
|
+
0 = "x" # Cross
|
|
135
|
+
1 = "z" # Circle
|
|
136
|
+
2 = "s" # Square
|
|
137
|
+
3 = "a" # Triangle
|
|
138
|
+
4 = "v" # Share
|
|
139
|
+
6 = "enter" # Options / START
|
|
140
|
+
9 = "q" # L1
|
|
141
|
+
10 = "e" # R1
|
|
142
|
+
11 = "up"
|
|
143
|
+
12 = "down"
|
|
144
|
+
13 = "left"
|
|
145
|
+
14 = "right"
|
|
146
|
+
|
|
147
|
+
[axes]
|
|
148
|
+
0 = ["f", "h"] # Left Stick X (neg, pos)
|
|
149
|
+
1 = ["t", "g"] # Left Stick Y
|
|
150
|
+
2 = ["j", "l"] # Right Stick X
|
|
151
|
+
3 = ["i", "k"] # Right Stick Y
|
|
152
|
+
|
|
153
|
+
[triggers]
|
|
154
|
+
4 = "tab" # L2
|
|
155
|
+
5 = "r" # R2
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Special key names: `enter`, `tab`, `up`, `down`, `left`, `right`, `space`, `esc`, `shift`, `ctrl`, `alt`. Single characters are used directly.
|
|
159
|
+
|
|
160
|
+
Profiles can be created or edited from the CLI with `new` and `edit`, or by copying and editing TOML files directly.
|
|
161
|
+
|
|
162
|
+
## Publishing to PyPI
|
|
163
|
+
|
|
164
|
+
This project uses [Trusted Publishing](https://docs.pypi.org/trusted-publishers/) via GitHub Actions. To release a new version:
|
|
165
|
+
|
|
166
|
+
1. Bump `version` in `pyproject.toml`.
|
|
167
|
+
2. Create a GitHub release — the `publish.yml` workflow builds and uploads the distribution automatically.
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# DS4 Mapper
|
|
2
|
+
|
|
3
|
+
Maps a DualShock 4 controller to keyboard inputs system-wide, so you can play browser games with a controller. Profiles are hot-swappable at runtime without restarting.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- Python 3.11+
|
|
8
|
+
- A DualShock 4 connected via Bluetooth
|
|
9
|
+
|
|
10
|
+
**macOS:** Grant Accessibility permission to your terminal in **System Settings → Privacy & Security → Accessibility** (required for keyboard injection).
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
From PyPI:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install ds4-mapper
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Or from source (development mode):
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
git clone https://github.com/jaredmahan/ds4-mapper.git
|
|
24
|
+
cd ds4-mapper
|
|
25
|
+
pip install -e ".[dev]"
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
Connect your DS4 via Bluetooth, then run:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
ds4-mapper
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Or without installing:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
python -m ds4mapper
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Options
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
--profile NAME Profile to load on startup (default: default)
|
|
46
|
+
--discover Print raw button/axis indices — useful for building new profiles
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Discover Mode
|
|
50
|
+
|
|
51
|
+
If a button isn't registering, use discover mode to see the raw event index:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
ds4-mapper --discover
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## CLI Commands
|
|
58
|
+
|
|
59
|
+
Once the mapper is running, type commands at the `>` prompt:
|
|
60
|
+
|
|
61
|
+
| Command | Effect |
|
|
62
|
+
|---------|--------|
|
|
63
|
+
| `list` | Show available profiles |
|
|
64
|
+
| `switch <name>` | Load a profile (Tab-completes) |
|
|
65
|
+
| `current` | Show the active profile name |
|
|
66
|
+
| `reload` | Reload the current profile from disk |
|
|
67
|
+
| `view [<name>]` | Show button/axis/trigger mappings for a profile |
|
|
68
|
+
| `edit [<name>]` | Open the profile editor for an existing profile |
|
|
69
|
+
| `new <name>` | Create a new profile in the editor |
|
|
70
|
+
| `help` | Show command list |
|
|
71
|
+
| `quit` / `exit` | Stop |
|
|
72
|
+
|
|
73
|
+
## Profile Editor
|
|
74
|
+
|
|
75
|
+
`edit` and `new` open an interactive editor screen where you can map controller inputs to keyboard keys:
|
|
76
|
+
|
|
77
|
+
1. **Press a DS4 button, stick, or trigger** — the editor enters *waiting* mode and prompts for a key.
|
|
78
|
+
2. **Press the keyboard key** you want it mapped to — the mapping is recorded.
|
|
79
|
+
3. Repeat for each input you want to map.
|
|
80
|
+
|
|
81
|
+
You can also type commands in the editor's input field:
|
|
82
|
+
|
|
83
|
+
| Command | Effect |
|
|
84
|
+
|---------|--------|
|
|
85
|
+
| `save [stem]` | Save to disk (optional custom filename) |
|
|
86
|
+
| `delete <input>` | Remove a mapping (e.g. `delete Cross`) |
|
|
87
|
+
| `name <text>` | Set the profile display name |
|
|
88
|
+
| `desc <text>` | Set the profile description |
|
|
89
|
+
| `cancel` | Discard changes and return to the main screen |
|
|
90
|
+
|
|
91
|
+
Keyboard injection is suspended while the editor is open so controller inputs don't fire game actions.
|
|
92
|
+
|
|
93
|
+
## Profiles
|
|
94
|
+
|
|
95
|
+
Profiles live in `ds4mapper/profiles/`. Each is a TOML file:
|
|
96
|
+
|
|
97
|
+
```toml
|
|
98
|
+
name = "default"
|
|
99
|
+
description = "Standard browser game layout"
|
|
100
|
+
|
|
101
|
+
[buttons]
|
|
102
|
+
0 = "x" # Cross
|
|
103
|
+
1 = "z" # Circle
|
|
104
|
+
2 = "s" # Square
|
|
105
|
+
3 = "a" # Triangle
|
|
106
|
+
4 = "v" # Share
|
|
107
|
+
6 = "enter" # Options / START
|
|
108
|
+
9 = "q" # L1
|
|
109
|
+
10 = "e" # R1
|
|
110
|
+
11 = "up"
|
|
111
|
+
12 = "down"
|
|
112
|
+
13 = "left"
|
|
113
|
+
14 = "right"
|
|
114
|
+
|
|
115
|
+
[axes]
|
|
116
|
+
0 = ["f", "h"] # Left Stick X (neg, pos)
|
|
117
|
+
1 = ["t", "g"] # Left Stick Y
|
|
118
|
+
2 = ["j", "l"] # Right Stick X
|
|
119
|
+
3 = ["i", "k"] # Right Stick Y
|
|
120
|
+
|
|
121
|
+
[triggers]
|
|
122
|
+
4 = "tab" # L2
|
|
123
|
+
5 = "r" # R2
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Special key names: `enter`, `tab`, `up`, `down`, `left`, `right`, `space`, `esc`, `shift`, `ctrl`, `alt`. Single characters are used directly.
|
|
127
|
+
|
|
128
|
+
Profiles can be created or edited from the CLI with `new` and `edit`, or by copying and editing TOML files directly.
|
|
129
|
+
|
|
130
|
+
## Publishing to PyPI
|
|
131
|
+
|
|
132
|
+
This project uses [Trusted Publishing](https://docs.pypi.org/trusted-publishers/) via GitHub Actions. To release a new version:
|
|
133
|
+
|
|
134
|
+
1. Bump `version` in `pyproject.toml`.
|
|
135
|
+
2. Create a GitHub release — the `publish.yml` workflow builds and uploads the distribution automatically.
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ds4-mapper
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Map a DualShock 4 controller to keyboard inputs with a live TUI
|
|
5
|
+
Author: Jared Mahan
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/jaredmahan/ds4-mapper
|
|
8
|
+
Project-URL: Repository, https://github.com/jaredmahan/ds4-mapper
|
|
9
|
+
Project-URL: Issues, https://github.com/jaredmahan/ds4-mapper/issues
|
|
10
|
+
Keywords: ds4,dualshock4,controller,keyboard,mapping,gamepad,pygame
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
14
|
+
Classifier: Operating System :: MacOS
|
|
15
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Games/Entertainment
|
|
20
|
+
Classifier: Topic :: Utilities
|
|
21
|
+
Requires-Python: >=3.11
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: pygame-ce
|
|
25
|
+
Requires-Dist: pynput
|
|
26
|
+
Requires-Dist: rich
|
|
27
|
+
Requires-Dist: textual
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: pytest; extra == "dev"
|
|
30
|
+
Requires-Dist: ruff; extra == "dev"
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
|
|
33
|
+
# DS4 Mapper
|
|
34
|
+
|
|
35
|
+
Maps a DualShock 4 controller to keyboard inputs system-wide, so you can play browser games with a controller. Profiles are hot-swappable at runtime without restarting.
|
|
36
|
+
|
|
37
|
+
## Requirements
|
|
38
|
+
|
|
39
|
+
- Python 3.11+
|
|
40
|
+
- A DualShock 4 connected via Bluetooth
|
|
41
|
+
|
|
42
|
+
**macOS:** Grant Accessibility permission to your terminal in **System Settings → Privacy & Security → Accessibility** (required for keyboard injection).
|
|
43
|
+
|
|
44
|
+
## Install
|
|
45
|
+
|
|
46
|
+
From PyPI:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pip install ds4-mapper
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Or from source (development mode):
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
git clone https://github.com/jaredmahan/ds4-mapper.git
|
|
56
|
+
cd ds4-mapper
|
|
57
|
+
pip install -e ".[dev]"
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Usage
|
|
61
|
+
|
|
62
|
+
Connect your DS4 via Bluetooth, then run:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
ds4-mapper
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Or without installing:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
python -m ds4mapper
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Options
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
--profile NAME Profile to load on startup (default: default)
|
|
78
|
+
--discover Print raw button/axis indices — useful for building new profiles
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Discover Mode
|
|
82
|
+
|
|
83
|
+
If a button isn't registering, use discover mode to see the raw event index:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
ds4-mapper --discover
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## CLI Commands
|
|
90
|
+
|
|
91
|
+
Once the mapper is running, type commands at the `>` prompt:
|
|
92
|
+
|
|
93
|
+
| Command | Effect |
|
|
94
|
+
|---------|--------|
|
|
95
|
+
| `list` | Show available profiles |
|
|
96
|
+
| `switch <name>` | Load a profile (Tab-completes) |
|
|
97
|
+
| `current` | Show the active profile name |
|
|
98
|
+
| `reload` | Reload the current profile from disk |
|
|
99
|
+
| `view [<name>]` | Show button/axis/trigger mappings for a profile |
|
|
100
|
+
| `edit [<name>]` | Open the profile editor for an existing profile |
|
|
101
|
+
| `new <name>` | Create a new profile in the editor |
|
|
102
|
+
| `help` | Show command list |
|
|
103
|
+
| `quit` / `exit` | Stop |
|
|
104
|
+
|
|
105
|
+
## Profile Editor
|
|
106
|
+
|
|
107
|
+
`edit` and `new` open an interactive editor screen where you can map controller inputs to keyboard keys:
|
|
108
|
+
|
|
109
|
+
1. **Press a DS4 button, stick, or trigger** — the editor enters *waiting* mode and prompts for a key.
|
|
110
|
+
2. **Press the keyboard key** you want it mapped to — the mapping is recorded.
|
|
111
|
+
3. Repeat for each input you want to map.
|
|
112
|
+
|
|
113
|
+
You can also type commands in the editor's input field:
|
|
114
|
+
|
|
115
|
+
| Command | Effect |
|
|
116
|
+
|---------|--------|
|
|
117
|
+
| `save [stem]` | Save to disk (optional custom filename) |
|
|
118
|
+
| `delete <input>` | Remove a mapping (e.g. `delete Cross`) |
|
|
119
|
+
| `name <text>` | Set the profile display name |
|
|
120
|
+
| `desc <text>` | Set the profile description |
|
|
121
|
+
| `cancel` | Discard changes and return to the main screen |
|
|
122
|
+
|
|
123
|
+
Keyboard injection is suspended while the editor is open so controller inputs don't fire game actions.
|
|
124
|
+
|
|
125
|
+
## Profiles
|
|
126
|
+
|
|
127
|
+
Profiles live in `ds4mapper/profiles/`. Each is a TOML file:
|
|
128
|
+
|
|
129
|
+
```toml
|
|
130
|
+
name = "default"
|
|
131
|
+
description = "Standard browser game layout"
|
|
132
|
+
|
|
133
|
+
[buttons]
|
|
134
|
+
0 = "x" # Cross
|
|
135
|
+
1 = "z" # Circle
|
|
136
|
+
2 = "s" # Square
|
|
137
|
+
3 = "a" # Triangle
|
|
138
|
+
4 = "v" # Share
|
|
139
|
+
6 = "enter" # Options / START
|
|
140
|
+
9 = "q" # L1
|
|
141
|
+
10 = "e" # R1
|
|
142
|
+
11 = "up"
|
|
143
|
+
12 = "down"
|
|
144
|
+
13 = "left"
|
|
145
|
+
14 = "right"
|
|
146
|
+
|
|
147
|
+
[axes]
|
|
148
|
+
0 = ["f", "h"] # Left Stick X (neg, pos)
|
|
149
|
+
1 = ["t", "g"] # Left Stick Y
|
|
150
|
+
2 = ["j", "l"] # Right Stick X
|
|
151
|
+
3 = ["i", "k"] # Right Stick Y
|
|
152
|
+
|
|
153
|
+
[triggers]
|
|
154
|
+
4 = "tab" # L2
|
|
155
|
+
5 = "r" # R2
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Special key names: `enter`, `tab`, `up`, `down`, `left`, `right`, `space`, `esc`, `shift`, `ctrl`, `alt`. Single characters are used directly.
|
|
159
|
+
|
|
160
|
+
Profiles can be created or edited from the CLI with `new` and `edit`, or by copying and editing TOML files directly.
|
|
161
|
+
|
|
162
|
+
## Publishing to PyPI
|
|
163
|
+
|
|
164
|
+
This project uses [Trusted Publishing](https://docs.pypi.org/trusted-publishers/) via GitHub Actions. To release a new version:
|
|
165
|
+
|
|
166
|
+
1. Bump `version` in `pyproject.toml`.
|
|
167
|
+
2. Create a GitHub release — the `publish.yml` workflow builds and uploads the distribution automatically.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
ds4_mapper.egg-info/PKG-INFO
|
|
5
|
+
ds4_mapper.egg-info/SOURCES.txt
|
|
6
|
+
ds4_mapper.egg-info/dependency_links.txt
|
|
7
|
+
ds4_mapper.egg-info/entry_points.txt
|
|
8
|
+
ds4_mapper.egg-info/requires.txt
|
|
9
|
+
ds4_mapper.egg-info/top_level.txt
|
|
10
|
+
ds4mapper/__init__.py
|
|
11
|
+
ds4mapper/__main__.py
|
|
12
|
+
ds4mapper/cli.py
|
|
13
|
+
ds4mapper/keys.py
|
|
14
|
+
ds4mapper/mapper.py
|
|
15
|
+
ds4mapper/profiles.py
|
|
16
|
+
ds4mapper/profiles/default.toml
|
|
17
|
+
tests/test_keys.py
|
|
18
|
+
tests/test_mapper.py
|
|
19
|
+
tests/test_profiles.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ds4mapper
|
|
File without changes
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import os
|
|
3
|
+
import sys
|
|
4
|
+
import time
|
|
5
|
+
|
|
6
|
+
os.environ["SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS"] = "1"
|
|
7
|
+
|
|
8
|
+
import pygame
|
|
9
|
+
|
|
10
|
+
from ds4mapper.cli import run
|
|
11
|
+
from ds4mapper.profiles import load_profile
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _init_pygame() -> pygame.joystick.Joystick:
|
|
15
|
+
pygame.init()
|
|
16
|
+
pygame.display.set_caption("DS4 Mapper")
|
|
17
|
+
pygame.display.set_mode((220, 40))
|
|
18
|
+
pygame.joystick.init()
|
|
19
|
+
|
|
20
|
+
if pygame.joystick.get_count() == 0:
|
|
21
|
+
timeout = 30
|
|
22
|
+
deadline = time.monotonic() + timeout
|
|
23
|
+
while pygame.joystick.get_count() == 0:
|
|
24
|
+
remaining = int(deadline - time.monotonic())
|
|
25
|
+
if remaining <= 0:
|
|
26
|
+
print("\rNo controller found. Connect the DS4 via Bluetooth and try again.")
|
|
27
|
+
sys.exit(1)
|
|
28
|
+
print(
|
|
29
|
+
f"\rNo controller detected. Waiting for DS4... {remaining}s ", end="", flush=True
|
|
30
|
+
)
|
|
31
|
+
pygame.event.pump()
|
|
32
|
+
time.sleep(1)
|
|
33
|
+
print() # newline after countdown
|
|
34
|
+
|
|
35
|
+
joy = pygame.joystick.Joystick(0)
|
|
36
|
+
joy.init()
|
|
37
|
+
print(f"Connected: {joy.get_name()}")
|
|
38
|
+
return joy
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _discover(joy: pygame.joystick.Joystick) -> None:
|
|
42
|
+
print("\nDiscover mode — press every button and move every stick/trigger.")
|
|
43
|
+
print("Ctrl-C to quit.\n")
|
|
44
|
+
while True:
|
|
45
|
+
for event in pygame.event.get():
|
|
46
|
+
if event.type == pygame.QUIT:
|
|
47
|
+
return
|
|
48
|
+
elif event.type == pygame.JOYBUTTONDOWN:
|
|
49
|
+
print(f" BUTTON DOWN index={event.button}")
|
|
50
|
+
elif event.type == pygame.JOYBUTTONUP:
|
|
51
|
+
print(f" BUTTON UP index={event.button}")
|
|
52
|
+
elif event.type == pygame.JOYHATMOTION:
|
|
53
|
+
print(f" HAT value={event.value}")
|
|
54
|
+
elif event.type == pygame.JOYAXISMOTION:
|
|
55
|
+
print(f" AXIS index={event.axis} value={event.value:.3f}")
|
|
56
|
+
time.sleep(0.016)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def main() -> None:
|
|
60
|
+
parser = argparse.ArgumentParser(description="DS4 → Keyboard Mapper")
|
|
61
|
+
parser.add_argument(
|
|
62
|
+
"--discover", action="store_true", help="Print raw events to verify button/axis indices"
|
|
63
|
+
)
|
|
64
|
+
parser.add_argument(
|
|
65
|
+
"--profile", default="default", help="Profile name to load on startup (default: default)"
|
|
66
|
+
)
|
|
67
|
+
args = parser.parse_args()
|
|
68
|
+
|
|
69
|
+
joy = _init_pygame()
|
|
70
|
+
try:
|
|
71
|
+
if args.discover:
|
|
72
|
+
print(f"Discover mode — {joy.get_name()}")
|
|
73
|
+
_discover(joy)
|
|
74
|
+
else:
|
|
75
|
+
profile = load_profile(args.profile)
|
|
76
|
+
run(joy, profile, args.profile)
|
|
77
|
+
except KeyboardInterrupt:
|
|
78
|
+
print("\nStopped.")
|
|
79
|
+
finally:
|
|
80
|
+
pygame.quit()
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
if __name__ == "__main__":
|
|
84
|
+
main()
|