Skip to content

Commit

Permalink
#1252 feat: add support for another camera button when the screen is off
Browse files Browse the repository at this point in the history
  • Loading branch information
sds100 committed Aug 4, 2024
1 parent c89bdd2 commit feef344
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ class DetectScreenOffKeyEventsController(
companion object {
private const val REGEX_GET_DEVICE_LOCATION = "/.*(?=:)"
private const val REGEX_KEY_EVENT_ACTION = "(?<= )(DOWN|UP)"

fun canDetectKeyWhenScreenOff(keyCode: Int): Boolean =
KeyEventUtils.GET_EVENT_LABEL_TO_KEYCODE.containsValue(keyCode)
}

private var job: Job? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import io.github.sds100.keymapper.data.entities.Extra
import io.github.sds100.keymapper.data.entities.TriggerEntity
import io.github.sds100.keymapper.data.entities.getData
import io.github.sds100.keymapper.mappings.ClickType
import io.github.sds100.keymapper.mappings.keymaps.detection.DetectScreenOffKeyEventsController
import io.github.sds100.keymapper.system.keyevents.KeyEventUtils
import io.github.sds100.keymapper.util.valueOrNull
import kotlinx.serialization.Serializable
import splitties.bitflags.hasFlag
Expand Down Expand Up @@ -40,14 +40,12 @@ data class KeyMapTrigger(

fun isLongPressDoubleVibrationAllowed(): Boolean =
(keys.size == 1 || (mode is TriggerMode.Parallel)) &&
keys.getOrNull(0)?.clickType == ClickType.LONG_PRESS
keys.getOrNull(0)?.clickType == ClickType.LONG_PRESS

fun isDetectingWhenScreenOffAllowed(): Boolean = keys.isNotEmpty() &&
keys.all {
DetectScreenOffKeyEventsController.canDetectKeyWhenScreenOff(
it.keyCode,
)
}
keys.all {
KeyEventUtils.canDetectKeyWhenScreenOff(it.keyCode)
}

fun isChangingSequenceTriggerTimeoutAllowed(): Boolean =
!keys.isNullOrEmpty() && keys.size > 1 && mode is TriggerMode.Sequence
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,11 @@ object KeyEventUtils {
KeyEvent.KEYCODE_ALL_APPS,
)

/**
* These are key code maps for the getevent command. These names aren't the same as the
* 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,
Expand All @@ -652,10 +657,14 @@ object KeyEventUtils {
"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,
)

fun canDetectKeyWhenScreenOff(keyCode: Int): Boolean =
KeyEventUtils.GET_EVENT_LABEL_TO_KEYCODE.containsValue(keyCode)

val MODIFIER_KEYCODES: Set<Int>
get() = setOf(
KeyEvent.KEYCODE_SHIFT_LEFT,
Expand Down

0 comments on commit feef344

Please sign in to comment.