Search Unity

Edit Mode Editor Scripts, bind NumKeys to Menu item's shortcuts

Discussion in 'Scripting' started by SLASH24, Jul 4, 2020.

  1. SLASH24

    SLASH24

    Joined:
    Sep 20, 2012
    Posts:
    144
    Hi There !!!

    In The HotKeys section (unity learn section : https://learn.unity.com/tutorial/editor-scripting#5c7f8528edbc2a002053b5f9), where it is explained how to bind shortcuts to Menu Items, I couldn't find a way to use and get NumPad Keys to work , (I mean numbers). if I write 6 in my editor script or even _6 ( for CTRL+6), it doesn't work. the editor seems to expect only the numbers from upper side of the keyboard but not the numbers from the NumPad... I need help to find a way to use NumPad number keys, thanks in advance...

    Code (CSharp):
    1. // Add a new menu item with hotkey G
    2. [MenuItem("Tools/Item2 _g")]
    3. private static void NewOptionWithHotkey()
    4. {
    5. }
     
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    If it did not change since 2012, there is no way to address numpad keys through hotkey text:
    https://answers.unity.com/questions/224603/numpad-keys-in-menuitem.html

    The documentation also only mentions that some special keys, such as shift, F1, Pgup, .. are supported.
    https://docs.unity3d.com/ScriptReference/MenuItem.html

    So if you must use the numpad, it's probably better to check for keypresses and use KeyCode, which does support both alpha and keypad keys separately.
    https://docs.unity3d.com/ScriptReference/KeyCode.html
     
  3. SLASH24

    SLASH24

    Joined:
    Sep 20, 2012
    Posts:
    144
    ok, thanks for the reply !