(var KEY_MAP [ =>"ZERO" "0" =>"ONE" "1" =>"TWO" "2" =>"THREE" "3" =>"FOUR" "4" =>"FIVE" "5" =>"SIX" "6" =>"SEVEN" "7" =>"EIGHT" "8" =>"NINE" "9" =>"NUMPADZERO" "0" =>"NUMPADONE" "1" =>"NUMPADTWO" "2" =>"NUMPADTHREE" "3" =>"NUMPADFOUR" "4" =>"NUMPADFIVE" "5" =>"NUMPADSIX" "6" =>"NUMPADSEVEN" "7" =>"NUMPADEIGHT" "8" =>"NUMPADNINE" "9" // TODO there are probably other keys worth converting ]) (defNew [] (super) (set cancelKey "escape") // TODO generic error handlers ) (prop &mut :Array buttonActions []) (method enableGamepadInput [:Map buttonToKeyMappings &opt :Int gamepadId] (unless gamepadId (set gamepadId FlxInputDeviceID.ALL)) (set buttonActions (for =>buttonId keyString buttonToKeyMappings (let [action (.addGamepad (new FlxActionDigital "${buttonId}->${keyString}") buttonId JUST_PRESSED gamepadId)] // capture the fake JUST_PRESSED event harmlessly (action.update) (set action.callback ->:Void _ (handleKey keyString)) action)))) (method :Void update [] (doFor action buttonActions (action.update)) // automatically pass the last pressed key to super.handleKey (let [:FlxKey id (FlxG.keys.firstJustPressed)] (unless (= id -1) (let [key (id.toString)] (case key ("SHIFT" (return)) (otherwise (handleKey (case key ((when (KEY_MAP.exists key) key) (dictGet KEY_MAP key)) ((when FlxG.keys.pressed.SHIFT key) (.toUpperCase key)) (key (.toLowerCase key)) (otherwise (throw "FlxKey.toString returned null!"))))))))))