aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes KeyListener - How do I know if the Question Mark key is pressed? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "KeyListener - How do I know if the Question Mark key is pressed?" Watch "KeyListener - How do I know if the Question Mark key is pressed?" New topic
Author

KeyListener - How do I know if the Question Mark key is pressed?

Stephen Bourget
Greenhorn

Joined: Aug 13, 2012
Posts: 5
I'm trying to make my own text editor in Java, but I've run into a problem when I try to type a question mark into my program.
With KeyEvent e,
e.getKeyChar() will return '?' when the question mark key is pressed, but also when a key such as shift or control is pressed.
Is it safe to assume that '?' is always the secondary character for a forward slash?
Am I missing something or doing something wrong?

Thanks.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
Not sure, but the KeyEvent documentation says there is no key code associated with ?
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4544
    
    5

To make your own text editor, you don't have to make your own text component. To what Swing or AWT component are you adding the KeyListener?


luck, db
There are no new questions, but there may be new answers.
Stephen Bourget
Greenhorn

Joined: Aug 13, 2012
Posts: 5
I read up a little and it seems any american keyboard will have a question mark as the secondary character for the forward slash, so ill just have to stick with that bandaid for now. It just seems odd that the getKeyChar will return '?' for keys like shift, ctrl, etc.
Stephen Bourget
Greenhorn

Joined: Aug 13, 2012
Posts: 5
@darryl
I'm learning java right now, and I'm pretty familiar with all of the built in components. I thought it would be fun to make my own from scratch. I'm just using a JFrame and a JPanel, and the graphics component for the JPanel.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Seems to me that internationalizing your program so that it can handle a variety of keyboards could be a challenging task. You might want to put that off until you get something functional working with the keyboard that you regularly use.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: KeyListener - How do I know if the Question Mark key is pressed?