Skip to content

Commit a66c39b

Browse files
committed
keymapperorg#1276 refactor: display change to scanCode fallback
1 parent 22a38b3 commit a66c39b

File tree

7 files changed

+34
-1
lines changed

7 files changed

+34
-1
lines changed

app/src/main/java/io/github/sds100/keymapper/data/Keys.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ object Keys {
4949
booleanPreferencesKey("key_shown_parallel_trigger_order_warning")
5050
val shownSequenceTriggerExplanation =
5151
booleanPreferencesKey("key_shown_sequence_trigger_explanation_dialog")
52+
val shownKeyCodeToScanCodeTriggerExplanation =
53+
booleanPreferencesKey("key_shown_keycode_to_scancode_trigger_explanation_dialog")
5254
val lastInstalledVersionCodeHomeScreen =
5355
intPreferencesKey("last_installed_version_home_screen")
5456
val lastInstalledVersionCodeBackground =

app/src/main/java/io/github/sds100/keymapper/mappings/keymaps/trigger/BaseConfigTriggerViewModel.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,20 @@ abstract class BaseConfigTriggerViewModel(
327327
// need to be dismissed before it is added.
328328
config.addKeyCodeTriggerKey(key.keyCode, key.device, key.detectionSource)
329329

330+
if (key.keyCode >= InputEventUtils.KEYCODE_TO_SCANCODE_OFFSET) {
331+
if (onboarding.shownKeyCodeToScanCodeTriggerExplanation) {
332+
return
333+
}
334+
335+
val dialog = PopupUi.Ok(
336+
message = getString(R.string.dialog_message_keycode_to_scancode_trigger_explanation),
337+
)
338+
339+
showPopup("keycode_to_scancode_message", dialog)
340+
341+
onboarding.shownKeyCodeToScanCodeTriggerExplanation = true
342+
}
343+
330344
if (key.keyCode == KeyEvent.KEYCODE_CAPS_LOCK) {
331345
val dialog = PopupUi.Ok(
332346
message = getString(R.string.dialog_message_enable_physical_keyboard_caps_lock_a_keyboard_layout),

app/src/main/java/io/github/sds100/keymapper/onboarding/OnboardingUseCase.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ class OnboardingUseCaseImpl(
6565
Keys.shownSequenceTriggerExplanation,
6666
false,
6767
)
68+
override var shownKeyCodeToScanCodeTriggerExplanation by PrefDelegate(
69+
Keys.shownKeyCodeToScanCodeTriggerExplanation,
70+
false,
71+
)
6872

6973
override val showWhatsNew = get(Keys.lastInstalledVersionCodeHomeScreen)
7074
.map { (it ?: -1) < Constants.VERSION_CODE }
@@ -164,6 +168,7 @@ interface OnboardingUseCase {
164168

165169
var shownParallelTriggerOrderExplanation: Boolean
166170
var shownSequenceTriggerExplanation: Boolean
171+
var shownKeyCodeToScanCodeTriggerExplanation: Boolean
167172

168173
val showAssistantTriggerFeatureNotification: Flow<Boolean>
169174
fun showedAssistantTriggerFeatureNotification()

app/src/main/java/io/github/sds100/keymapper/system/inputevents/InputEventUtils.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,12 +686,21 @@ object InputEventUtils {
686686
KeyEvent.KEYCODE_FUNCTION,
687687
)
688688

689+
/**
690+
* Used for keyCode to scanCode fallback to go past possible keyCode values
691+
*/
692+
const val KEYCODE_TO_SCANCODE_OFFSET: Int = 1000
693+
689694
/**
690695
* Create a text representation of a key event. E.g if the control key was pressed,
691696
* "Ctrl" will be returned
692697
*/
693698
fun keyCodeToString(keyCode: Int): String = NON_CHARACTER_KEY_LABELS[keyCode].let {
694-
it ?: "unknown keycode $keyCode"
699+
if (keyCode >= KEYCODE_TO_SCANCODE_OFFSET) {
700+
"scancode $keyCode"
701+
} else {
702+
it ?: "unknown keycode $keyCode"
703+
}
695704
}
696705

697706
fun isModifierKey(keyCode: Int): Boolean = keyCode in MODIFIER_KEYCODES

app/src/main/res/values-pl/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@
382382
<string name="dialog_message_double_press_restricted_to_single_key">"Wielu klawiszy nie można jednocześnie nacisnąć dwukrotnie."</string>
383383
<string name="dialog_message_parallel_trigger_order">Klawisze muszą być ułożone od góry do dołu w kolejności, w jakiej będą przytrzymywane.</string>
384384
<string name="dialog_message_sequence_trigger_explanation">Wyzwalacz \"kolejkowy\" ma limit czasu w przeciwieństwie do wyzwalaczy równoległych. Oznacza to, że po naciśnięciu pierwszego klawisza jest określony czas na wprowadzenie pozostałych. Wszystkie klawisze, które zostały dodane do wyzwalacza, nie będą wykonywać swojej zwykłej czynności, dopóki nie zostanie przekroczony limit czasu. Ten limit można zmienić na karcie \"Opcje\".</string>
385+
<string name="dialog_message_keycode_to_scancode_trigger_explanation">Naciśnięty przycisk nie został rozpoznany przez system wejściowy. W przeszłości Key Mapper wykrywał takie przyciski jako jeden i ten sam. Obecnie aplikacja próbuje rozróżnić przycisk na podstawie kodu skanowania, który powinien być bardziej unikalny. Jest to jednak prowizoryczne, niekompletne rozwiązanie, które nie gwarantuje unikalności.</string>
385386
<string name="dialog_message_bt_constraint_limitation">Android nie pozwala aplikacjom na odczytywanie listy aktualnie połączonych (niesparowanych) urządzeń Bluetooth. Aplikacje mogą je wykrywać tylko w momencie, gdy się łączą i rozłączają. Dlatego jeśli urządzenie Bluetooth było już połączone z urządzeniem w momencie uruchomienia usługi ułatwień dostępu, konieczne będzie ponowne połączenie, aby aplikacja mogła je wykryć.</string>
386387
<string name="dialog_message_change_location_or_disable">Zmienić lokalizację lub wyłączyć automatyczną kopię zapasową?</string>
387388
<string name="dialog_message_screen_constraints_limitation">Ograniczenia \"Ekran jest włączony/wyłączony\" będą działać tylko wtedy, gdy jest włączona opcja mapy klawiszy \"Wykryj trigger gdy ekran jest wyłączony\". Ta opcja będzie wyświetlana tylko dla niektórych klawiszy (np. przycisków głośności) i jeśli masz uprawnienia root. Zobacz listę obsługiwanych klawiszy na stronie pomocy.</string>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@
501501
<string name="dialog_message_double_press_restricted_to_single_key">"Multiple keys can't be double pressed at the same time."</string>
502502
<string name="dialog_message_parallel_trigger_order">The keys need to be listed from top to bottom in the order that they will be held down.</string>
503503
<string name="dialog_message_sequence_trigger_explanation">A \"sequence\" trigger has a timeout unlike parallel triggers. This means after you press the first key, you will have a set amount of time to input the rest of the keys in the trigger. All the keys that you have added to the trigger won\'t do their usual action until the timeout has been reached. You can change this timeout in the "Options" tab.</string>
504+
<string name="dialog_message_keycode_to_scancode_trigger_explanation">The pressed button was not recognized by the input system. In the past Key Mapper detected such buttons as one and the same. Currently the app tries to distinguish the button based on the scan code, which should be more unique. However, this is a makeshift incomplete solution, which doesn\'t guarantee uniqueness.</string>
504505
<string name="dialog_message_bt_constraint_limitation">Android doesn\'t allow apps to get a list of connected (not paired) Bluetooth devices. Apps can only detect when they are connected and disconnected. So if your Bluetooth device is already connected to your device when the accessibility service starts, you will have to reconnect it for the app to know it is connected.</string>
505506
<string name="dialog_message_change_location_or_disable">Change location or turn off automatic back up?</string>
506507
<string name="dialog_message_screen_constraints_limitation">Screen on/off constraints will only work if you have turned on the \"detect trigger when screen is off\" key map option. This option will only show for some keys (e.g volume buttons) and if you are rooted. See a list of supported keys on the Help page.</string>

app/src/test/java/io/github/sds100/keymapper/onboarding/FakeOnboardingUseCase.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class FakeOnboardingUseCase : OnboardingUseCase {
2626

2727
override var shownParallelTriggerOrderExplanation: Boolean = false
2828
override var shownSequenceTriggerExplanation: Boolean = false
29+
override var shownKeyCodeToScanCodeTriggerExplanation: Boolean = false
2930
override val showAssistantTriggerFeatureNotification: Flow<Boolean> = MutableStateFlow(false)
3031

3132
override fun showedAssistantTriggerFeatureNotification() {}

0 commit comments

Comments
 (0)