Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Stephen Bourget
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50225
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure, but the KeyEvent documentation says there is no key code associated with ?
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Stephen Bourget
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic