Skip to content

Commit a73e118

Browse files
committed
fix: regression that broke support for hardware keyboard handling in Direct Input
should fix #67
1 parent f056958 commit a73e118

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

app/src/main/java/me/arianb/usb_hid_client/input_views/DirectInputKeyboardView.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,23 @@ fun DirectInput(
7171

7272
etDirectInput.setKeySender(keySender)
7373

74-
// For some reason, the input connection doesn't receive media keys, so i'm listening for them here
75-
// and just passing them through
74+
// For some reason, the input connection doesn't receive media keys, but this listener *does*, so
75+
// I'm listening for them here and just passing them through.
76+
//
77+
// As another note, this key listener seems to be triggered all the time when the key is sent from a
78+
// hardware keyboard (during admittedly limited testing).
7679
etDirectInput.setOnKeyListener { _, keyCode, event ->
7780
Timber.d("OnKeyListener received KeyEvent: %s", event.toString())
7881
// If key is a media key and user doesn't want us to pass it through, then just
79-
// ignore it and let the system handle it normally
82+
// ignore it and let the system handle it normally. Otherwise, send it.
8083
// TODO: rename this preference to "media key passthrough" or something similar since that's more accurate
8184
if (KeyCodeTranslation.isMediaKey(keyCode)) {
82-
if (userPreferencesState.isVolumeButtonPassthroughEnabled) {
83-
return@setOnKeyListener etDirectInput.sendKeyEvent(event)
85+
if (!userPreferencesState.isVolumeButtonPassthroughEnabled) {
86+
return@setOnKeyListener false
8487
}
8588
}
86-
false
89+
90+
return@setOnKeyListener etDirectInput.sendKeyEvent(event)
8791
}
8892
}
8993
)

0 commit comments

Comments
 (0)