diff --git a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/detection/DetectScreenOffKeyEventsController.kt b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/detection/DetectScreenOffKeyEventsController.kt index 06f0a4921d..2ebd0ff17e 100644 --- a/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/detection/DetectScreenOffKeyEventsController.kt +++ b/app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/detection/DetectScreenOffKeyEventsController.kt @@ -59,8 +59,6 @@ class DetectScreenOffKeyEventsController( deviceLocationToDeviceMap[deviceLocation] = device } - val getEventLabels = KeyEventUtils.GET_EVENT_LABEL_TO_KEYCODE.keys - val deviceLocationRegex = Regex(REGEX_GET_DEVICE_LOCATION) val actionRegex = Regex(REGEX_KEY_EVENT_ACTION) @@ -71,16 +69,12 @@ class DetectScreenOffKeyEventsController( var line: String? while (inputStream.bufferedReader().readLine() - .also { line = it } != null && - isActive + .also { line = it } != null && isActive ) { line ?: continue - getEventLabels.forEach { label -> - if (line?.contains(label) == true) { - val keyCode = KeyEventUtils.GET_EVENT_LABEL_TO_KEYCODE[label] - ?: return@forEach - + KeyEventUtils.GET_EVENT_LABEL_TO_KEYCODE.forEach { (label, keyCode) -> + if (line!!.contains(label)) { val deviceLocation = deviceLocationRegex.find(line!!)?.value ?: return@forEach @@ -105,8 +99,6 @@ class DetectScreenOffKeyEventsController( ) } } - - return@forEach } } } diff --git a/app/src/main/java/io/github/sds100/keymapper/system/keyevents/KeyEventUtils.kt b/app/src/main/java/io/github/sds100/keymapper/system/keyevents/KeyEventUtils.kt index e8e9c4dee9..d9a68cade2 100644 --- a/app/src/main/java/io/github/sds100/keymapper/system/keyevents/KeyEventUtils.kt +++ b/app/src/main/java/io/github/sds100/keymapper/system/keyevents/KeyEventUtils.kt @@ -649,21 +649,26 @@ object KeyEventUtils { * KeyEvent key codes in the Android SDK so these have to be manually whitelisted * as people need. */ - val GET_EVENT_LABEL_TO_KEYCODE: Map - get() = mapOf( - "KEY_VOLUMEDOWN" to KeyEvent.KEYCODE_VOLUME_DOWN, - "KEY_VOLUMEUP" to KeyEvent.KEYCODE_VOLUME_UP, - "KEY_MEDIA" to KeyEvent.KEYCODE_HEADSETHOOK, - "KEY_HEADSETHOOK" to KeyEvent.KEYCODE_HEADSETHOOK, - "KEY_CAMERA_FOCUS" to KeyEvent.KEYCODE_FOCUS, - "02fe" to KeyEvent.KEYCODE_CAMERA, - "00fa" to KeyEvent.KEYCODE_CAMERA, - "02bf" to KeyEvent.KEYCODE_MENU, - "KEY_SEARCH" to KeyEvent.KEYCODE_SEARCH, - ) + val GET_EVENT_LABEL_TO_KEYCODE: List> = listOf( + "KEY_VOLUMEDOWN" to KeyEvent.KEYCODE_VOLUME_DOWN, + "KEY_VOLUMEUP" to KeyEvent.KEYCODE_VOLUME_UP, + "KEY_MEDIA" to KeyEvent.KEYCODE_HEADSETHOOK, + "KEY_HEADSETHOOK" to KeyEvent.KEYCODE_HEADSETHOOK, + "KEY_CAMERA_FOCUS" to KeyEvent.KEYCODE_FOCUS, + "02fe" to KeyEvent.KEYCODE_CAMERA, + "00fa" to KeyEvent.KEYCODE_CAMERA, + + // This kernel key event code seems to be the Bixby button + // but different ROMs have different key maps and so + // it is reported as different Android key codes. + "02bf" to KeyEvent.KEYCODE_MENU, + "02bf" to KeyEvent.KEYCODE_ASSIST, + + "KEY_SEARCH" to KeyEvent.KEYCODE_SEARCH, + ) fun canDetectKeyWhenScreenOff(keyCode: Int): Boolean = - KeyEventUtils.GET_EVENT_LABEL_TO_KEYCODE.containsValue(keyCode) + GET_EVENT_LABEL_TO_KEYCODE.any { it.second == keyCode } val MODIFIER_KEYCODES: Set get() = setOf( diff --git a/docs/includes/trigger-options/trigger-when-screen-off.md b/docs/includes/trigger-options/trigger-when-screen-off.md index c858b5e04a..0cb2b46997 100644 --- a/docs/includes/trigger-options/trigger-when-screen-off.md +++ b/docs/includes/trigger-options/trigger-when-screen-off.md @@ -12,5 +12,5 @@ also like to be supported. * Headset button * Camera focus button * Camera button -* Menu button (on some devices the Bixby button is detected by Key Mapper as a menu button) +* Bixby button - on some ROMs the Bixby button is mapped to the Menu or Assist key code in Android so it will appear as these buttons in the trigger. * Search button \ No newline at end of file