Should KeyInput+KeyNames be deprecated in favor to an enum?

Well… topic says all :slight_smile:

Besides readability and “smartness”, it is currently impossible to get variable name from numeric value (for example, KEY_A from 0x1E).

Sure, you can get user friendly name with KeyNames, but you must store it in numeric value (and I prefer store them in human readable format: as I said, KEY_A).

Uhm… on a second thought, maybe not. It makes code verbose and is useful only when remapping

There are other issues as well. It would break all existing JME apps that don’t recompile… and would break some of them that do. It would definitely break all Lemur apps.

Also, the key codes themselves are integers at the lowest level coming out of the keyboard/driver. The OS does minimal interpretation. (And I actually think it’s a bit of a mistake that JME filters them instead of just passing them on but I guess someone felt it safer.) JME’s key codes directly match the ones defined at the lower levels… which may have gaps, etc…

An enum to cover all of this would be very verbose indeed.

As to the patch, I’m not sure I understand when or why you’d ever need to let a user know that the key is called VK_F. If you are just using it for your mapping files then you should maybe use reflection instead… and you might consider supporting the human readable names also.

You mean that the mapping file of a game should look like:

mario.jump=32

rather than

mario.jump=KEY_F1

I think the latter is way better. You never know, an actual human might want to take a look…

1 Like

No, with reflection you can see all of the field names.

I personally think:
mario.jump=F1
…would be even better, though.

1 Like

Or at least the pr could do the Lookup with the already existing Array

   //new system
   String val="F1";
    for (int i=0;i<0xff;i++)
        if (KeyNames.getName(i).equals(val))
            return i;
    return KeyInput.KEY_UNKNOWN;

    // old system
    //return KeyInput.class.getField(props.getProperty(key, deflt)).getInt(null);

Well… that’s it.

1 Like

Sorry for asking. Is “mapping files” an official feature? Where to find best information (wiki entry?) Thanks.

That (by the way) is reflection. (getField method). Used it a bunch of times.

An official feature of BigBanana, of course!

On the forum post that I’ll write when is usable.

You quoted my code. I should know what I write… or at least I hope so :stuck_out_tongue:
I have to admit that sometimes I don’t know what I write even on the forum…

1 Like

Haha, this reminds me of something borderline stupid I did a while ago to have key names display on the gui key rebinder.

	public static HashMap<Integer,String> keys = new HashMap<Integer,String>();
	
	private static void addKey(String s,int x){
		keys.put(x, s);
	}
	
	static{
		addKey("UNKNOWN",0);
		addKey("ESCAPE",1);
		addKey("1",2);
		addKey("2",3);
		addKey("3",4);
		addKey("4",5);
		addKey("5",6);
		addKey("6",7);
		addKey("7",8);
		addKey("8",9);
		addKey("9",10);
		addKey("0",11);
		addKey("MINUS",12);
		addKey("EQUALS",13);
		addKey("BACK",14);
		addKey("TAB",15);
		addKey("Q",16);
		addKey("W",17);
		addKey("E",18);
		addKey("R",19);
		addKey("T",20);
		addKey("Y",21);
		addKey("U",22);
		addKey("I",23);
		addKey("O",24);
		addKey("P",25);
		addKey("LBRACKET",26);
		addKey("RBRACKET",27);
		addKey("RETURN",28);
		addKey("LCONTROL",29);
		addKey("A",30);
		addKey("S",31);
		addKey("D",32);
		addKey("F",33);
		addKey("G",34);
		addKey("H",35);
		addKey("J",36);
		addKey("K",37);
		addKey("L",38);
		addKey("SEMICOLON",39);
		addKey("APOSTROPHE",40);
		addKey("GRAVE",41);
		addKey("LSHIFT",42);
		addKey("BACKSLASH",43);
		addKey("Z",44);
		addKey("X",45);
		addKey("C",46);
		addKey("V",47);
		addKey("B",48);
		addKey("N",49);
		addKey("M",50);
		addKey("COMMA",51);
		addKey("PERIOD",52);
		addKey("SLASH",53);
		addKey("RSHIFT",54);
		addKey("MULTIPLY",55);
		addKey("LALT",56);
		addKey("SPACE",57);
		addKey("CAPITAL",58);
		addKey("F1",59);
		addKey("F2",60);
		addKey("F3",61);
		addKey("F4",62);
		addKey("F5",63);
		addKey("F6",64);
		addKey("F7",65);
		addKey("F8",66);
		addKey("F9",67);
		addKey("F10",68);
		addKey("NUMLOCK",69);
		addKey("SCROLL",70);
		addKey("NUMPAD7",71);
		addKey("NUMPAD8",72);
		addKey("NUMPAD9",73);
		addKey("SUBTRACT",74);
		addKey("NUMPAD4",75);
		addKey("NUMPAD5",76);
		addKey("NUMPAD6",77);
		addKey("ADD",78);
		addKey("NUMPAD1",79);
		addKey("NUMPAD2",80);
		addKey("NUMPAD3",81);
		addKey("NUMPAD0",82);
		addKey("DECIMAL",83);
		addKey("F11",87);
		addKey("F12",88);
		addKey("F13",100);
		addKey("F14",101);
		addKey("F15",102);
		addKey("KANA",112);
		addKey("CONVERT",121);
		addKey("NOCONVERT",123);
		addKey("YEN",125);
		addKey("NUMPADEQUALS",141);
		addKey("CIRCUMFLEX",144);
		addKey("AT",145);
		addKey("COLON",146);
		addKey("UNDERLINE",147);
		addKey("KANJI",148);
		addKey("STOP",149);
		addKey("AX",150);
		addKey("UNLABELED",151);
		addKey("NUMPADENTER",156);
		addKey("RCONTROL",157);
		addKey("NUMPADCOMMA",179);
		addKey("DIVIDE",181);
		addKey("SYSRQ",183);
		addKey("RALT",184);
		addKey("PAUSE",197);
		addKey("HOME",199);
		addKey("UP",200);
		addKey("PRIOR",201);
		addKey("PGUP",201);
		addKey("LEFT",203);
		addKey("RIGHT",205);
		addKey("END",207);
		addKey("DOWN",208);
		addKey("NEXT",209);
		addKey("PGDN",209);
		addKey("INSERT",210);
		addKey("DELETE",211);
		addKey("LMETA",219);
		addKey("RMETA",220);
		addKey("APPS",221);
		addKey("POWER",222);
		addKey("SLEEP",223);
		addKey("LAST",224);
	}

I vaguely recall formating this with a regex, being as long as it is. If it’s stupid and it works :smile:

It seems to basically duplicate what’s already there, though, doesn’t it?

It’s close…

    addKey("SEMICOLON",39);
	addKey("APOSTROPHE",40);
	addKey("GRAVE",41);
	addKey("LSHIFT",42);
	addKey("BACKSLASH",43);

	addKey("PERIOD",52);
	addKey("SLASH",53);
	addKey("RSHIFT",54);
	addKey("MULTIPLY",55);
	addKey("LALT",56);
	addKey("SPACE",57);
	addKey("CAPITAL",58);

very close.

    KEY_NAMES[KEY_MINUS] = "-";
    KEY_NAMES[KEY_EQUALS] = "=";
    KEY_NAMES[KEY_LBRACKET] = "[";
    KEY_NAMES[KEY_RBRACKET] = "]";
    KEY_NAMES[KEY_SEMICOLON] = ";";
    KEY_NAMES[KEY_APOSTROPHE] = "'";
    KEY_NAMES[KEY_GRAVE] = "`";
    KEY_NAMES[KEY_BACKSLASH] = "\\";
    KEY_NAMES[KEY_COMMA] = ",";
    KEY_NAMES[KEY_PERIOD] = ".";
    KEY_NAMES[KEY_SLASH] = "/";
    KEY_NAMES[KEY_MULTIPLY] = "*";
    KEY_NAMES[KEY_ADD] = "+";
    KEY_NAMES[KEY_COLON] = ":";
    KEY_NAMES[KEY_UNDERLINE] = "_";
    KEY_NAMES[KEY_AT] = "@";

For some reason I wanted some keys to write out differently and it was easier to just redo the whole thing. Not sure why I wanted that but ¯\_(ツ)_/¯. Probably something related to my font not having some chars I would think.