Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8396265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:29:36+00:00 2026-06-09T20:29:36+00:00

I’m attempting to write a dynamic keybind system for a java game. It mostly

  • 0

I’m attempting to write a dynamic keybind system for a java game. It mostly works, except for one huge problem: characters like a, b ,c don’t work. Only characters like ~, &, $ work.

I call the method with KeyFinder lookup = KeyFinder.lookup(keyChar);

Here is my current code file, sorry if this is really long.

KeyFinder.java

public enum KeyFinder {
    A(Keyboard.KEY_A, "a", "A"),
    B(Keyboard.KEY_B, "b", "B"),
    C(Keyboard.KEY_C, "c", "C"),
    D(Keyboard.KEY_D, "d", "D"),
    E(Keyboard.KEY_E, "e", "E"),
    F(Keyboard.KEY_F, "f", "F"),
    G(Keyboard.KEY_G, "g", "G"),
    H(Keyboard.KEY_H, "h", "H"),
    I(Keyboard.KEY_I, "i", "I"),
    J(Keyboard.KEY_J, "j", "J"),
    K(Keyboard.KEY_K, "k", "K"),
    L(Keyboard.KEY_L, "l", "L"),
    M(Keyboard.KEY_M, "m", "M"),
    N(Keyboard.KEY_N, "n", "N"),
    O(Keyboard.KEY_O, "o", "O"),
    P(Keyboard.KEY_P, "p", "P"),
    Q(Keyboard.KEY_Q, "q", "Q"),
    R(Keyboard.KEY_R, "r", "R"),
    S(Keyboard.KEY_S, "s", "S"),
    T(Keyboard.KEY_T, "t", "T"),
    U(Keyboard.KEY_U, "u", "U"),
    V(Keyboard.KEY_V, "v", "V"),
    W(Keyboard.KEY_W, "w", "W"),
    X(Keyboard.KEY_X, "x", "X"),
    Y(Keyboard.KEY_Y, "y", "Y"),
    Z(Keyboard.KEY_Z, "z", "Z"),
    TILDE(Keyboard.KEY_GRAVE, "~", "`"),
    TAB(Keyboard.KEY_TAB, "tab"),
    F1(Keyboard.KEY_F1, "F1"),
    F2(Keyboard.KEY_F2, "F2"),
    F3(Keyboard.KEY_F3, "F3"),
    F4(Keyboard.KEY_F4, "F4"),
    F5(Keyboard.KEY_F5, "F5"),
    F6(Keyboard.KEY_F6, "F6"),
    F7(Keyboard.KEY_F7, "F7"),
    F8(Keyboard.KEY_F8, "F8"),
    F9(Keyboard.KEY_F9, "F9"),
    F10(Keyboard.KEY_F10, "F10"),
    F11(Keyboard.KEY_F11, "F11"),
    F12(Keyboard.KEY_F12, "F12"),
    F13(Keyboard.KEY_F13, "F13"),
    F14(Keyboard.KEY_F14, "F14"),
    F15(Keyboard.KEY_F15, "F15"),
    ONE(Keyboard.KEY_1, "1", "!", "one"),
    TWO(Keyboard.KEY_2, "2", "@", "two"),
    THREE(Keyboard.KEY_3, "3", "#", "three"),
    FOUR(Keyboard.KEY_4, "4", "$", "four"),
    FIVE(Keyboard.KEY_5, "5", "%", "five"),
    SIX(Keyboard.KEY_6, "6", "^", "six"),
    SEVEN(Keyboard.KEY_7, "7", "&", "seven"),
    EIGHT(Keyboard.KEY_8, "8", "*", "eight"),
    NINE(Keyboard.KEY_9, "9", "(", "nine"),
    ZERO(Keyboard.KEY_0, "0", ")", "zero"),
    MINUS(Keyboard.KEY_MINUS, "-", "_", "minus"),
    EQUALS_ADD(Keyboard.KEY_EQUALS, "=", "+", "plus", "equals"),
    INSERT(Keyboard.KEY_INSERT, "insert", "ins"),
    DEL(Keyboard.KEY_DELETE, "del", "delete"),
    HOME(Keyboard.KEY_HOME, "home"),
    ADD(Keyboard.KEY_ADD, "add"),
    PAGE_UP(Keyboard.KEY_PRIOR, "prior", "pageup"),
    PAGE_DOWN(Keyboard.KEY_NEXT, "next", "pagedown"),
    NUM_LOCK(Keyboard.KEY_NUMLOCK, "numlock", "numberlock"),
    SQBRACKET_LEFT(Keyboard.KEY_LBRACKET, "[", "{"),
    SQBRACKET_RIGHT(Keyboard.KEY_RBRACKET, "]", "}"),
    SEMICOLON(Keyboard.KEY_SEMICOLON, ";", ":");
    private static final Map<Integer, KeyFinder> keys = new HashMap<Integer, KeyFinder>();
    private static final Map<String, KeyFinder> lookup = new LinkedHashMap<String, KeyFinder>();
    private final int key;
    private final String keyName;
    private final String[] lookupKeys;
    static {
        for (KeyFinder type : EnumSet.allOf(KeyFinder.class)) {
            keys.put(type.key, type);
            for (String key : type.lookupKeys) {
                lookup.put(key, type);
            }
        }
    }

    KeyFinder(int key, String keyName, String lookupKey) {
        this.key = key;
        this.keyName = keyName;
        this.lookupKeys = new String[] { lookupKey };
    }

    KeyFinder(int key, String keyName, String... lookupKeys) {
        this.key = key;
        this.keyName = keyName;
        this.lookupKeys = lookupKeys;
    }

    public static KeyFinder fromKey(int key) {
        return keys.get(key);
    }

    public static String toKeyName(int key) {
        KeyFinder type = keys.get(key);
        if (type != null) {
            return type.getKeyName();
        } else {
            return "#" + key;
        }
    }

    public static KeyFinder lookup(String keyName) {
        return lookup(keyName, true);
    }

    public static KeyFinder lookup(String keyName, boolean fuzzy) {
        KeyFinder i = StringUtil.lookup(lookup, keyName, fuzzy);
        if(i != null)
            return i;
        else
            try {
                return fromKey(Integer.parseInt(keyName));
            } catch (NumberFormatException e) {
                return null;
            }
    }

    public int getKey() {
        return key;
    }

    public String getKeyName() {
        return keyName;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:29:38+00:00Added an answer on June 9, 2026 at 8:29 pm

    I stripped down your KeyFinder and tested together with the StringUtil and realize that you never ever use the keyName in your lookup map. So a is not there.

    Here are some changes I did which might help you.

    Change the lookupKeys to be a list instead of an array.

    private final ArrayList<String> lookupKeys = new ArrayList<String>();
    

    Remove one of your constructors (it is obsolete since you have one with varargs)

    KeyFinder(int key, String keyName, String lookupKey) // Remove
    

    Change the other constructor and let keyName be included in the lookupKeys.

    KeyFinder(int key, String keyName, String... lookupKeys) {
        this.key = key;
        this.keyName = keyName;
        this.lookupKeys.add(keyName);
        this.lookupKeys.addAll(Arrays.asList(lookupKeys));
    }
    

    It worked for me in some simple tests.

    NB

    I have not analyzed your code more than this. I don’t know if you actually need the keyName but I leave that up to you. I just wanted the lookup to work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I have a text area in my form which accepts all possible characters from
I am currently running into a problem where an element is coming back from
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.