• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Key Listeners

 
Cody Long
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Fred Hamilton
Ranch Hand
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
perhaps this page will help

http://leepoint.net/notes-java/GUI-lowlevel/keyboard/keyboard.html
 
Rob Camick
Ranch Hand
Posts: 2613
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am using a JTextField to write the caracters to and putting the listeners on
 
Rob Camick
Ranch Hand
Posts: 2613
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, my answer still stands.
 
Cody Long
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is a document filter and how do you use it?
 
Rob Camick
Ranch Hand
Posts: 2613
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2613
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic