EsotericSoftware / spine-editor

Issue tracking for the Spine editor.
http://esotericsoftware.com/
28 stars 2 forks source link

The `Strength+` and `Strength-` hotkeys for weights do not work #798

Open misaki-eymard opened 1 month ago

misaki-eymard commented 1 month ago

Description: The following hotkeys for changing the Strength for Add or Remove Weight mode does not seem to be working:

Expected behavior: When you are selecting Add or Remove in the weight view, you can change the Strength using the corresponding hotkey.

Steps to reproduce:

  1. Open Spine 4.2.29 and create new project.
  2. Open the Weight view and set the mode to Add or Remove.
  3. Press the Strength+ or Strength- hotkey.

The version of Spine in which this issue was found: Spine 4.2.29

NathanSweet commented 1 month ago

I find it works on Windows. Maybe this is a macOS bug.

misaki-eymard commented 1 month ago

Sorry, my test was not sufficient. I confirmed that it works if you change the default key to another key, although I tried it on Mac PC. Changing the following key settings made it work: Weights - Strength+: N Weights - Strength-: O

Also, I found that even with the default key settings, holding down ctrl works. There should be no reason why "opt + key" combinations should not work, since hotkeys for opening views, such as opt + A to open the Animation view, work. So in any case, I think there may be some issues specific to Mac PCs.

davidetan commented 1 month ago

The problem is related to the fact that when you press opt on Mac, then you get another character:

Also:

However during hotkeys initialization there is an important difference. In Hotkeys#load the hotkeys are initialized like this:

Keycode is 0 for the first two cases because the code doesn't enter this if (repeat is true):

if (!repeat || keyName.length() != 1) {
    try {
        keycode = (Integer)Input.Keys.class.getField(keyName).get(null);
    } catch (Throwable ex) {
        errors.add($("Invalid key name: ") + originalKeyName);
    }
}

and in any case it seems there is no mapping available in Input.Keys for the two keys above.

Consequently, when Hotkeys.fire(char character) is triggered typing opt + ', we receive æ as character and the line:

Array<Hotkey> charHotkeys = characterToHotkeys.get(character);

won't find the keyword corresponding to opt + '. This is confirmed by the fact that if I change the hotkey to opt + æ, they hotkeys is triggered.

The reason why typing opt + A works even though it sends the character å, is because there is also the Hotkeys.fire(int keycode). Pressing opt + A will send the keycode 29 that is registered in the hotkeys. The line:

Array<Hotkey> keycodeHotkeys = keycodeToHotkeys.get(keycode);

is able to find the corresponding keycode.