aboutsummaryrefslogtreecommitdiff
path: root/marsond.rst
blob: 756d54dbfe1067cc017cba436ae7dcad521f52aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219

.. |version| replace:: 0.3.0
.. |date| date::

=======
marsond
=======

----------------------------------------------------------------
Fix Enter key timing on Marson/USBLink/MT606-1 PS/2-USB adaptors
----------------------------------------------------------------

:Manual section: 8
:Manual group: Urchlay's Stuff
:Date: |date|
:Version: |version|

SYNOPSIS
========

marsond [**-d** *delay-ms**] [**-f**] [**-k** *keyboard-device*] [**-p** *pause_ms* [**-v**] | [**--help**] | [**--version**] | [**-V**]

DESCRIPTION
===========

**marsond** fixes an issue with a particular model of PS/2 => USB
keyboard adaptor. The symptom: in games and emulators, the Enter key
only works sometimes. This is caused by the firmware in the adaptor
sending the keypress and release events only 8 milliseconds apart.
See the **NOTES** section for full details.

For normal use, **marsond** will be started by a **udev**\(7) rule
when the adaptor is plugged in (including booting with the adaptor
connected). The udev rule is found in:

  /etc/udev/rules.d/99-marsond.rules

...which can be edited to change the options it's run with, if
needed. The defaults work well on the author's system.

OPTIONS
=======

Options can be "bundled": **-vf** is the same as **-v** **-f**.

-d delay-ms
  Amount of time in milliseconds to delay the Enter key release events.
  Default: 30.

.. delay time for Enter key relase (default 30).

-f
  Run in the foreground; do not detach from the terminal or become a
  daemon. In this mode, **marsond** can be killed with *^C*.

.. run in foreground, not as a daemon.

-k keyboard-device
  Input device for the keyboard adaptor. Default:
  /dev/input/by-id/usb-Marson_Marson_Keyboard_and_Mouse_Link_Ver:ps2120L-event-kbd

.. keyboard device (usually under /dev/input/by-id/).

-p pause-ms
  Amount of time in milliseconds to pause at startup, before opening the
  keyboard and uinput devices. May be useful on slow systems, if
  **marsond** won't consistently start from udev, but works fine
  if started manually. Default: 0.

.. pause before opening keyboard/uinput devs (default 0).

-v
  Verbose debugging mode. Prints copious trace information to **stderr**.
  Debugging mode is turned off when **marsond** forks itself into the
  background as a daemon. If you want to debug the event loop, combine
  **-v** and **-f**.

.. verbose debugging.

-h, --help
  Shows built-in usage message and exits.

.. this help text.

-V, --version
  Shows version number and exits.

.. show version number.

ENVIRONMENT
===========

MARSOND_USER
  After initialization, **marsond** will drop privileges by
  setting its user ID to this user's. Default: *nobody*

MARSOND_GROUP
  Group to run as, after dropping privileges. Default:
  the primary group of the user it's running as. Normally
  you won't have to set this.

NOTES
=====

Hardware
--------

The problem happens with any SDL application (SDL1 or SDL2), as well
as other graphics libraries. It happens regardless of what PS/2
keyboard you have plugged in, what computer you have the adaptor
plugged into, or what OS that computer is running.

The specific hardware that has the Enter key problem for me is USB
vendor ID 04b4, product ID 0101, "Marson Keyboard and Mouse Link
Ver:ps2120L". It has a label on the front that says "USBLink", and on
the back, the model number is "MT606-1". It looks like:

  https://slackware.uk/~urchlay/sdl-usblink-hack/marson-front.jpg

  https://slackware.uk/~urchlay/sdl-usblink-hack/marson-back.jpg

Confusingly enough, in **lsusb**\(8) output, it shows up as::

  $ lsusb | grep 04b4:0101
  Bus 003 Device 006: ID 04b4:0101 Cypress Semiconductor Corp. Keyboard/Hub

The Bus and Device numbers may be different for you, it's the ID and
name that are important.

I'm not sure if any other USB keyboard adaptors are affected. If
you have the problem on some other adaptor, try it with **marsond**.
Use the **-k** option to set the */dev/input/by-id* name of the device,
and run the daemon manually. If this fixes it please contact me so I
can add support for your adaptor in the future.

Implementation
--------------

**marsond** uses the Linux kernel's **uinput** layer to "grab" the
keyboard, create a new virtual keyboard device, and pass events from
the real keyboard to the virtual one. When it sees the key release
event for the Enter key, it simply pauses for a few milliseconds
before delivering it.

This should work with everything that uses the keyboard. It definitely
does, with SDL 1 and 2 running under X (and SDL 1 on the console,
too). It should also work with Wayland, though I don't use Wayland,
so I haven't tested it there. If you do, please contact me and let me
know whether or not it works for you.

Startup
-------

**marsond** must be run as root. At startup, it does these
things as root:

- Grab the physical keyboard.

- Create the virtual keyboard device.

- Lock its pages into physical memory, to avoid being swapped out.

- Set its priority (nice value) to -20 (highest priority), to
  avoid slow response on a loaded system.

After doing the above, root access is no longer needed, so it will
drop privileges and run as the *nobody* user by default (but see
**ENVIRONMENT** if you need a different user).

Misc
----

While **marsond** is running, "xinput --list" will show an input
device called "marson virtual keyboard", listed as a keyboard.

LIMITATIONS
===========

Only one MT-606-1 device is supported, out of the box. This shouldn't
really be a problem (do you really need 2 keyboards?) but it's worth
mentioning. If you really do own two of these adaptors and want to use
them on the same PC, you could add a second udev rule (with -k option
for the daemon).

This isn't really a **marsond** problem per se, but when Xorg detects
a new keyboard, it resets your keyboard repeat rate (**xset r**)
and custom keymap (**xmodmap**\(1)). If you use a 'desktop' such
as KDE, GNOME, or XFCE, it should re-apply your settings. For a
traditional window manager (WindowMaker, FVWM2, etc), this can be very
annoying.

.. EXIT STATUS
.. ===========

.. BUGS
.. ====

.. EXAMPLES
.. ========

COPYRIGHT
=========

WTFPL. Short version: do WTF you want. Full version:

  http://www.wtfpl.net/txt/copying/

AUTHORS
=======

B. Watson <urchlay@slackware.uk>

SEE ALSO
========

The homepage: https://slackware.uk/~urchlay/repos/marsond

Another solution to the problem, less complete, but should be portable
to non-Linux OSes: https://slackware.uk/~urchlay/sdl-usblink-hack/