Skip to content

Commit ba6d96b

Browse files
committed
#753 fix: Remapping modifier keys breaks existing modifier key shortcuts so automatically enable the "do not remap" trigger key option for modifier keys
1 parent d925152 commit ba6d96b

File tree

4 files changed

+77
-10
lines changed

4 files changed

+77
-10
lines changed

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,24 @@ class ConfigKeyMapUseCaseImpl(
6262
}
6363
}
6464

65-
val newKeys = trigger.keys.toMutableList().apply {
65+
val newKeys = trigger.keys.toMutableList()
6666

67-
val triggerKey = TriggerKey(
68-
keyCode = keyCode,
69-
device = device,
70-
clickType = clickType
71-
)
67+
var consumeKeyEvent = true
7268

73-
add(triggerKey)
69+
//Issue #753
70+
if (KeyEventUtils.isModifierKey(keyCode)) {
71+
consumeKeyEvent = false
7472
}
7573

74+
val triggerKey = TriggerKey(
75+
keyCode = keyCode,
76+
device = device,
77+
clickType = clickType,
78+
consumeKeyEvent = consumeKeyEvent
79+
)
80+
81+
newKeys.add(triggerKey)
82+
7683
val newMode = when {
7784
containsKey -> TriggerMode.Sequence
7885
newKeys.size <= 1 -> TriggerMode.Undefined

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@
703703

704704
<string name="flag_hold_down">Hold down</string>
705705
<string name="flag_hold_down_until_pressed_again">Hold down until pressed again</string>
706-
<string name="flag_dont_override_default_action">Do not override default action</string>
706+
<string name="flag_dont_override_default_action">Do not remap</string>
707707
<string name="flag_hold_down_until_swiped_again">Hold down until swiped again</string>
708708
<string name="flag_trigger_from_other_apps">Allow other apps to trigger this key map</string>
709709
<!--flags-->

app/src/test/java/io/github/sds100/keymapper/ConfigKeyMapUseCaseTest.kt

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import io.github.sds100.keymapper.actions.TapCoordinateAction
66
import io.github.sds100.keymapper.mappings.keymaps.ConfigKeyMapUseCaseImpl
77
import io.github.sds100.keymapper.mappings.keymaps.KeyMap
88
import io.github.sds100.keymapper.mappings.keymaps.KeyMapAction
9+
import io.github.sds100.keymapper.mappings.keymaps.trigger.TriggerKeyDevice
910
import io.github.sds100.keymapper.system.keyevents.KeyEventUtils
1011
import io.github.sds100.keymapper.util.State
1112
import io.github.sds100.keymapper.util.dataOrNull
@@ -48,6 +49,60 @@ class ConfigKeyMapUseCaseTest {
4849
testDispatcher.cleanupTestCoroutines()
4950
}
5051

52+
/**
53+
* Issue #753. If a modifier key is used as a trigger then it the
54+
* option to not override the default action must be chosen so that the modifier
55+
* key can still be used normally.
56+
*/
57+
@Test
58+
fun `when add modifier key trigger, enable do not remap option`() =
59+
coroutineScope.runBlockingTest {
60+
val modifierKeys = setOf(
61+
KeyEvent.KEYCODE_SHIFT_LEFT,
62+
KeyEvent.KEYCODE_SHIFT_RIGHT,
63+
KeyEvent.KEYCODE_ALT_LEFT,
64+
KeyEvent.KEYCODE_ALT_RIGHT,
65+
KeyEvent.KEYCODE_CTRL_LEFT,
66+
KeyEvent.KEYCODE_CTRL_RIGHT,
67+
KeyEvent.KEYCODE_META_LEFT,
68+
KeyEvent.KEYCODE_META_RIGHT,
69+
KeyEvent.KEYCODE_SYM,
70+
KeyEvent.KEYCODE_NUM,
71+
KeyEvent.KEYCODE_FUNCTION
72+
)
73+
74+
for (modifierKeyCode in modifierKeys) {
75+
//GIVEN
76+
useCase.mapping.value = State.Data(KeyMap())
77+
78+
//WHEN
79+
useCase.addTriggerKey(modifierKeyCode, TriggerKeyDevice.Internal)
80+
81+
//THEN
82+
val trigger = useCase.mapping.value.dataOrNull()!!.trigger
83+
84+
assertThat(trigger.keys[0].consumeKeyEvent, `is`(false))
85+
}
86+
}
87+
88+
/**
89+
* Issue #753.
90+
*/
91+
@Test
92+
fun `when add non-modifier key trigger, do ont enable do not remap option`() =
93+
coroutineScope.runBlockingTest {
94+
//GIVEN
95+
useCase.mapping.value = State.Data(KeyMap())
96+
97+
//WHEN
98+
useCase.addTriggerKey(KeyEvent.KEYCODE_A, TriggerKeyDevice.Internal)
99+
100+
//THEN
101+
val trigger = useCase.mapping.value.dataOrNull()!!.trigger
102+
103+
assertThat(trigger.keys[0].consumeKeyEvent, `is`(true))
104+
}
105+
51106
/**
52107
* issue #593
53108
*/

docs/user-guide/keymaps.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,18 @@ External devices are only listed if they are connected to your Android device wh
5252

5353
This menu pops up if you press the 3 dot :fontawesome-solid-ellipsis-v: button on a key.
5454

55-
#### Do not override default action
55+
#### Do not remap
5656

5757
--8<-- "trigger-options/dont-override-default-action.md"
5858

59+
This option doesn't remap the trigger key, which means it will continue do its normal thing when clicked as well as your
60+
action. This will be automatically
61+
5962
#### Click type
6063

61-
This will change the click type for a key in a sequence trigger. A parallel trigger key will not have the click type option because all the keys have the same click type. You will find the buttons to change a parallel trigger's click type above the trigger mode buttons as shown in the image at the top of this Trigger section.
64+
This will change the click type for a key in a sequence trigger. A parallel trigger key will not have the click type
65+
option because all the keys have the same click type. You will find the buttons to change a parallel trigger's click
66+
type above the trigger mode buttons as shown in the image at the top of this Trigger section.
6267

6368
## Customising actions
6469

0 commit comments

Comments
 (0)