• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure, but the KeyEvent documentation says there is no key code associated with ?
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic