This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Does anybody know how I would go about extending the KeyEvent class to create some new VK fields for new keys? Thanks. Paul
Cindy Glass
"The Hood"
Sheriff
Joined: Sep 29, 2000
Posts: 8521
posted
0
Personally I would extract the KeyEvent class from your src.jar file and swipe some code. So I did these are the VK_ fields as defined for windows:
public static final int VK_ENTER = '\n'; public static final int VK_BACK_SPACE = '\b'; public static final int VK_TAB = '\t'; public static final int VK_CANCEL = 0x03; public static final int VK_CLEAR = 0x0C; public static final int VK_SHIFT = 0x10; public static final int VK_CONTROL = 0x11; public static final int VK_ALT = 0x12; public static final int VK_PAUSE = 0x13; public static final int VK_CAPS_LOCK = 0x14; public static final int VK_ESCAPE = 0x1B; public static final int VK_SPACE = 0x20; public static final int VK_PAGE_UP = 0x21; public static final int VK_PAGE_DOWN = 0x22; public static final int VK_END = 0x23; public static final int VK_HOME = 0x24; public static final int VK_LEFT = 0x25; public static final int VK_UP = 0x26; public static final int VK_RIGHT = 0x27; public static final int VK_DOWN = 0x28; public static final int VK_COMMA = 0x2C; public static final int VK_MINUS = 0x2D; public static final int VK_PERIOD = 0x2E; public static final int VK_SLASH = 0x2F; /** VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
public static final int VK_0 = 0x30; public static final int VK_1 = 0x31; public static final int VK_2 = 0x32; public static final int VK_3 = 0x33; etc, public static final int VK_SEMICOLON = 0x3B; public static final int VK_EQUALS = 0x3D; /** VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */
public static final int VK_A = 0x41; public static final int VK_B = 0x42; public static final int VK_C = 0x43; etc. public static final int VK_OPEN_BRACKET = 0x5B; public static final int VK_BACK_SLASH = 0x5C; public static final int VK_CLOSE_BRACKET = 0x5D; public static final int VK_NUMPAD0 = 0x60; public static final int VK_NUMPAD1 = 0x61; public static final int VK_NUMPAD2 = 0x62; etc. public static final int VK_MULTIPLY = 0x6A; public static final int VK_ADD = 0x6B; public static final int VK_SEPARATER = 0x6C; public static final int VK_SUBTRACT = 0x6D; public static final int VK_DECIMAL = 0x6E; public static final int VK_DIVIDE = 0x6F; public static final int VK_DELETE = 0x7F; /* ASCII DEL */
public static final int VK_NUM_LOCK = 0x90; public static final int VK_SCROLL_LOCK = 0x91; etc. etc. for pages and pages
Of course these only work because the underlying operating system recogizes these hex codes as control commands already. Then there is a GIANT switch statement with stuff like: case VK_DELETE: return Toolkit.getProperty("AWT.delete", "Delete"); case VK_NUM_LOCK: return Toolkit.getProperty("AWT.numLock", "Num Lock"); case VK_SCROLL_LOCK: return Toolkit.getProperty("AWT.scrollLock", "Scroll Lock"); etc. etc. You will be hard put to ADD new commands, however CHANGING existing commands within the scope of your application is possible. Did you see the NUMPAD numbers? Maybe you can catch those and convert them to their "other" use, like catching VK_NUMPAD8 and swapping it for VK_UP.
"JavaRanch, where the deer and the Certified play" - David O'Meara