Adding (left/right) shift, alt, control to keyboard inputs.



  • HI,

    I wish to bind the left and right control keys to separate functions. The default FlxKeyList does not seem to provide them. I've already made this list based upon their ASCII codes.

    class ExtraKeyList extends flixel.input.keyboard.FlxKeyList {
        public var SHIFT_LEFT(get, never):Bool; inline function get_SHIFT_LEFT() {return check(0x4b);}
        public var SHIFT_RIGHT(get, never):Bool; inline function get_SHIFT_RIGHT() {return check(0x56);}
        public var CONTROL_LEFT(get, never):Bool; inline function get_CONTROL_LEFT() {return check(0x5c);}
        public var CONTROL_RIGHT(get, never):Bool; inline function get_CONTROL_RIGHT() {return check(0x60);}
        public var ALT_LEFT(get, never):Bool; inline function get_ALT_LEFT() {return check(0x5f);}
        public var ALT_RIGHT(get, never):Bool; inline function get_ALT_RIGHT() {return check(0x5d);}
        public var WIN_LEFT(get, never):Bool; inline function get_WIN_LEFT() {return check(0x66);}
        public var WIN_RIGHT(get, never):Bool; inline function get_WIN_RIGHT() {return check(0x67);}
    }
    

    But how can I make haxeflixel FlxG use this list instead of the default? Or am I going the wrong way on this and is there perhaps a better way to use these keys.?

    Many thanks for any help anyone might have.!



  • This post is deleted!


  • Small update: If i paste the above code in the original FlxKeyList then on runtime the app crashes if i press one of the buttons and says:

    invalid key code: 92
    

    For now I will accept the fact that these keys are not single assignable, but I would still love a solution for this.! So if anyone has any, please let me know!

    Thanks!



  • Good News Everyone,

    I've found a workaround. If you setup an event yourself from openfl. Then it can be done.

    import openfl.events.KeyboardEvent;
    import flixel.FlxG;
    
    // .... Setup the callbacks somewhere
    FlxG.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
    FlxG.stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
        
    // ... When the key goes up.
    public function onKeyUp(e:KeyboardEvent) { }
    
    // When the key goes down.
    public function onKeyDown(e:KeyboardEvent) {
        if (e.keyCode==17) { // 17 is the control key
            if (e.keyLocation==0) { // keyLocation gives Left + Right
                // 0 == right
            } else if (e.keyLocation==1) {
                // 1 == left
            }
        }
    }

Log in to reply
 

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.