tmk / tmk_keyboard

Keyboard firmwares for Atmel AVR and Cortex-M
3.98k stars 1.7k forks source link

Mouse key doesn't work with TAP_KEY #675

Closed tmk closed 1 year ago

tmk commented 3 years ago

Keycode of Mouse keys don't work with ACTION_LAYER_TAP_KEY() and ACTION_MODS_TAP_KEY().

https://github.com/tmk/tmk_keyboard/blob/06d354c06b473864ddc97ca347a6d4ffd00bbda3/tmk_core/common/keycode.h#L489-L507

register_code() and unregister_code() ignore Mouse keys(F0-FF) currently but they can be changed so that the codes are processed like System and Media keys.

https://github.com/tmk/tmk_keyboard/blob/06d354c06b473864ddc97ca347a6d4ffd00bbda3/tmk_core/common/action.c#L446-L451

ACTION_MOUSEKEY() is not needed anymore

ACTION_MOUSEKEY() can be used to define mouse actions but it is not needed once the [un]register_code() are fixed. https://github.com/tmk/tmk_keyboard/blob/06d354c06b473864ddc97ca347a6d4ffd00bbda3/tmk_core/common/action_code.h#L232 https://github.com/tmk/tmk_keyboard/blob/dd316b990f4523c49a0d1eef677cee67318d123d/tmk_core/common/actionmap.h#L289-L305

Mouse keys can be defined as normal keys, ACTION_KEY(KC_MS_UP) for example.

So ACTION_MOUSEKEY() and ACT_MOUSEKEY can be removed from Action codes. https://github.com/tmk/tmk_keyboard/blob/06d354c06b473864ddc97ca347a6d4ffd00bbda3/tmk_core/common/action_code.h#L50-L51

tmk commented 3 years ago

These values(0xF0-F3) conflict with mousekey keycodes: KC_MS_UP - KC_MS_RIGHT.

https://github.com/tmk/tmk_keyboard/blob/06d354c06b473864ddc97ca347a6d4ffd00bbda3/tmk_core/common/action_code.h#L250-L254

https://github.com/tmk/tmk_keyboard/blob/06d354c06b473864ddc97ca347a6d4ffd00bbda3/tmk_core/common/action_code.h#L72-L81

Instead, 0xE8-EF seems to be suit for this purpose, they are not used at this time.

Changing mousekey keycodes seem to be better for backward compatibility. 0xD0-DF can be used for new mousekeys. Range C0-DF are already used for ACTION_LAYER_MODS.

Note that this change requires Keymap Editor code fix.

tmk commented 3 years ago

This branch should be merged after Keymap Editor fix.

branch: https://github.com/tmk/tmk_keyboard/tree/mousekey_fix

https://github.com/tmk/tmk_keyboard/commit/cdf37f22e53ee1b1d79d3df50cbfc48ad9a65b72

tmk commented 3 years ago

Keyamp Editor Fix

Action Op values

These values should be changed to resolve conflict with mousekeys.

Value of enum layer_pram_tap_op:

Action Old New
OP_TAP_TOGGLE F0 E8
OP_ON_OFF F1 E9
OP_OFF_ON F2 EA
OP_SET_CLEAR F3 EB
OP_MOMENTARY F1 E9

Mousekey Action codes

ACTION_MOUSEKEY() is removed.

For example:

Old:
ACTION_MOUSEKEY(KC_MS_UP) = 0x50F0
where KC_MS_UP = 0xF0, ACTION_MOUSEKEY = 0x50

New:
ACTION_KEY(KC_MS_UP) = 0x00D0
where KC_MS_UP = 0xD0, ACTION_KEY = 0x00
Old New
ACTION_MOUSEKEY(KC_MS_UP) ACTION_KEY(KC_MS_UP)
ACTION_MOUSEKEY(KC_MS_DOWN) ACTION_KEY(KC_MS_DOWN)
ACTION_MOUSEKEY(KC_MS_LEFT) ACTION_KEY(KC_MS_LEFT)
ACTION_MOUSEKEY(KC_MS_RIGHT) ACTION_KEY(KC_MS_RIGHT)
ACTION_MOUSEKEY(KC_MS_BTN1) ACTION_KEY(KC_MS_BTN1)
ACTION_MOUSEKEY(KC_MS_BTN2) ACTION_KEY(KC_MS_BTN2)
ACTION_MOUSEKEY(KC_MS_BTN3) ACTION_KEY(KC_MS_BTN3)
ACTION_MOUSEKEY(KC_MS_BTN4) ACTION_KEY(KC_MS_BTN4)
ACTION_MOUSEKEY(KC_MS_BTN5) ACTION_KEY(KC_MS_BTN5)
ACTION_MOUSEKEY(KC_MS_WH_UP) ACTION_KEY(KC_MS_WH_UP)
ACTION_MOUSEKEY(KC_MS_WH_DOWN) ACTION_KEY(KC_MS_WH_DOWN)
ACTION_MOUSEKEY(KC_MS_WH_LEFT) ACTION_KEY(KC_MS_WH_LEFT)
ACTION_MOUSEKEY(KC_MS_WH_RIGHT) ACTION_KEY(KC_MS_WH_RIGHT)
ACTION_MOUSEKEY(KC_MS_ACCEL0) ACTION_KEY(KC_MS_ACCEL0)
ACTION_MOUSEKEY(KC_MS_ACCEL1) ACTION_KEY(KC_MS_ACCEL1)
ACTION_MOUSEKEY(KC_MS_ACCEL2) ACTION_KEY(KC_MS_ACCEL2)

Old keymap support

Translate actions above into new ones when Keymap Editor loads old keymap

How to identify between old and new keymap

Translate old into new action when loading old keymap

tmk commented 3 years ago

CONFLICT ACTIONS

These actions in old keymap will not be handled correctly in Keymap Editor.

OP_* values need to be modified in Keymap Editor and after

OP_TAP_TOGGLE: F0(MS_U) -> E8

OP_ON_OFF: F1(MS_D) -> E9

OP_OFF_ON: F2(MS_L) -> EA

OP_SET_CLEAR: F3(MS_R) -> EB

Prebuilt firmware files

All prebuilt files need to be updated when Keymap Editor is fixed.

tmk commented 1 year ago

FIXED and NOTES

Fixed with this commit: cdf37f22e53

Mousekeys work with ACTION_KEY(), ACTION_MODS_KEY(), ACTION_MODS_TAP_KEY() now.

But not completely with ACTION_LAYER_TAP_KEY(), enum layer_param_bit_op { OP_TAP_TOGGLE, OP_ON_OFF, OP_OFF_ON, OP_SET_CLEAR }(F0-F3) overlaps with mousekeys KC_MS_U, KC_MS_D, KC_MS_L and KC_MS_R partially. These mousekeys won't be useful much and rarely used with the action, though. Resolving this conflict breaks old keymap/firmware and it is not worth a lot of annoyance at this point.

ACT_MOUSEKEY can be removed but kept for backward compatibility.

Keymap Editor: ACTION_MOUSEKEY is still needed for backward compatibility in Keymap Editor. Old firmwares do not support ACTION_KEY(mousekey).