aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Key Listeners Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Key Listeners" Watch "Key Listeners" New topic
Author

Key Listeners

Cody Long
Ranch Hand

Joined: Jan 01, 2009
Posts: 95
I am trying to write a program that takes the key you type and changes it to something else. i cannot figure out what the key codes are for the letter keys. iny help will be great.



here are the keys i need to change:
a-z

0-9

thanks!!!

edit: i found the way to do it for the upper case letters but i cant find it for the lower case letters. when i do

it cannot find VK_a but when i use VK_A and use A instead of a it works. i need to be able to do it for the lowercase versions
also for some reason when i use the "/" in a string it says inproper close statement or something to that effect


Duct tape is like the Force. It has a dark side, a light side, and it binds the whole universe together.
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
perhaps this page will help

http://leepoint.net/notes-java/GUI-lowlevel/keyboard/keyboard.html
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2092
    
    7
I don't know what the context of your question is, but I'm assuming you are using a text component of some kind, in which case you should be using a DocumentFilter to translate each character.
Cody Long
Ranch Hand

Joined: Jan 01, 2009
Posts: 95
i am using a JTextField to write the caracters to and putting the listeners on
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2092
    
    7
Well, my answer still stands.
Cody Long
Ranch Hand

Joined: Jan 01, 2009
Posts: 95
what is a document filter and how do you use it?
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2092
    
    7
what is a document filter


Did you try Google?

and how do you use it?


The Swing tutorial gives an example (although I'm sure there are other examples on the net as well)
Cody Long
Ranch Hand

Joined: Jan 01, 2009
Posts: 95
Yes, i tried Google. couldn't find anything that a semi-intermediate java coder could understand.
Same with the swing tutorial. I couldn't under stand it.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
bookmark this page

http://java.sun.com/docs/books/tutorial/uiswing/TOC.html

find the link to writing a DocumentListener, at the top of that page is another link to a DocumentFilter
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
Cody Long wrote:Yes, i tried Google. couldn't find anything that a semi-intermediate java coder could understand.
Same with the swing tutorial. I couldn't under stand it.


IMO the Sun Tutorial is not the easiest thing to decipher sometimes. Often assumptions are made that the student understands the background material.

If you do decide to continue with the DocumentFilter angle, here is an example I found that maps lower case letters to uppercase letters that might be a useful complement to the Sun Tutorial. I haven't tried the example myself, so I can't speak directly as to its applicability.

http://www.java2s.com/Code/Java/Swing-JFC/DocumentFilterthatmapslowercaseletterstouppercase.htm
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2092
    
    7
Same with the swing tutorial. I couldn't under stand it


The tutorial comes with a working example and basic explanation of what the code does. Why would you think our examples would be any better?

You haven't stated "what you don't understand" so again we can't help because we don't know what needs clarification.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Key Listeners
 
Similar Threads
Dispose
Help writting to file
JPanel painComponent not working
Help With Repaint Method
Please help with this program