Gravit Designer discussion

GKey.translateKey returning wrong value for CMD (mac)


Here are some examples of GD internal key codes, with their respective dom key codes:

GKey.Constant.SHIFT = 6; // dom key code: 16
GKey.Constant.CONTROL  = 5; // dom key code: 17
GKey.Constant.META = 100; // dom key code: 91

GKey.translateKey does not translate CMD (91) correctly, a case for that is missing in the switch

GKey.translateKey(16); // returns  6, correct
GKey.translateKey(17); // returns  5, correct
GKey.translateKey(91); // returns  '[', wrong, should return 100

Is there something I am missing, or is it actually a bug. Can I circumvent this other than manually checking? Are there other codes missing in that switch case?


1 Like

Hi, @owzim. That is happening because the key 91 is not mapped on the switch case, so it returns the value using the method String.fromCharCode. Seems like GKey.Constant.OPTION is also missing, but you can use GPlatform.modifiers to check if those are pressed.