From 76f088e3fefed6a70ff242f9f1fff1cb2ce229a0 Mon Sep 17 00:00:00 2001 From: j3kestrel Date: Wed, 5 May 2021 14:30:28 -0400 Subject: [PATCH] Allow re-scan of devices to support hot-plugging The use of a bare generator in `EVENT_MAP['type_codes']` makes `EVENT_MAP` a single use object. Converting the generator to a tuple allows reuse of `EVENT_MAP` and constructing a new `DeviceManager` that re-scans for devices. --- inputs.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/inputs.py b/inputs.py index b1f8fb1..c4b5f74 100644 --- a/inputs.py +++ b/inputs.py @@ -1299,7 +1299,7 @@ def convert_timeval(seconds_since_epoch): EVENT_MAP = ( ('types', EVENT_TYPES), - ('type_codes', ((value, key) for key, value in EVENT_TYPES)), + ('type_codes', tuple((value, key) for key, value in EVENT_TYPES)), ('wincodes', WINCODES), ('specials', SPECIAL_DEVICES), ('xpad', XINPUT_MAPPING), @@ -3677,3 +3677,7 @@ def get_gamepad(): except IndexError: raise UnpluggedError("No gamepad found.") return gamepad.read() + +def rescan_devices(): + global devices + devices = DeviceManager()