Skip to content

Commit

Permalink
Merge pull request #1283 from keymapperorg/1282-add-assist-key-code-a…
Browse files Browse the repository at this point in the history
…s-screen-off-trigger

1282 add assist key code as screen off trigger
  • Loading branch information
sds100 authored Aug 28, 2024
2 parents 5d2f9f9 + 49d1743 commit 8403537
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

Expand All @@ -105,8 +99,6 @@ class DetectScreenOffKeyEventsController(
)
}
}

return@forEach
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Int>
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<Pair<String, Int>> = 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<Int>
get() = setOf(
Expand Down
2 changes: 1 addition & 1 deletion docs/includes/trigger-options/trigger-when-screen-off.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 8403537

Please sign in to comment.