Results 1 to 1 of 1
- 08-17-2009, 03:59 PM #1Member
- Join Date
- Aug 2009
- Rep Power
Brainbox needed -- KeyEvent VK_* constants stable??!
I'm newish to Java and I've found myself totally flummoxed by something in the documentation that I don't see how can physically make sense, besides the fact that if it did it wouldn't be sensible. I'd really appreciate insight from more knowledgeable folks.
My gripe is with the java.awt.event.KeyEvent api. It defines lots of virtual key code constants for use with the getKeyCode() function. This seemed perfect for what I need (binding some key controls for a game emulator, and loading and storing them from a config file).
Then to my total horror, I saw this note in the documentation:
Originally Posted by Sun idiots
This is totally useless for any sort of permanent key binding, which I need to do to store the keys into a file and have them not break in future VMs. So I made THIS monstrosity to define better constants: pastebin.com/f73084f4f (you'll have to copy & paste the link, sorry, but the forum software wouldn't let me type a link with a 0 post count).
Once I'd updated the rest of my code to use it, it worked perfectly. Then, just to check something, I decided to open up the compiled .class file in Notepad. But the VK_* identifiers are nowhere to be found. They've apparently been inlined by the compiler. I got a disassembler and checked again, and yes, the enums are being initialized like this (with fricking ASCII codes, of all the unrelated things to number virtual key constants with):
A = new StableKey("A", 11, 65); B = new StableKey("B", 12, 66); C = new StableKey("C", 13, 67); D = new StableKey("D", 14, 68); E = new StableKey("E", 15, 69); ..etcetera..
By the way, I'm using the ordinary javac that came with the Sun JDK. I've not run the code through any external optimizer.
Please help. :(
- By Java Tip in forum java.langReplies: 0Last Post: 04-17-2008, 07:39 PM
- By Java Tip in forum Java TipReplies: 0Last Post: 02-17-2008, 10:06 AM
- By bugger in forum New To JavaReplies: 3Last Post: 12-03-2007, 01:12 PM
- By goldhouse in forum Java SoftwareReplies: 0Last Post: 04-02-2007, 02:27 PM