Results 1 to 5 of 5
Thread: Reading Keyboard
- 08-20-2008, 03:26 AM #1Member
- Join Date
- Aug 2008
- Rep Power
Easy question I realize, but for some reason nobody has made a legitimate tutorial for it...
I just want to know how to check if a certain key (okay a couple different keys) has been pressed, and if it has, it calls a function. If it matters this is for JFrame, not console.
Thanks in advance.
- 08-20-2008, 04:09 AM #3
Look at keyListeners. These will capture keyboard input key events.
- Look at keyListeners. These will capture keyboard input key events.
"An alternative to key bindings is using key listeners. Key listeners have their place as a low-level interface to keyboard input, but for responding to individual keys key bindings are more appropriate and tend to result in more easily maintained code. Key listeners are also difficult if the key binding is to be active when the component doesn't have focus. Some of the advantages of key bindings are they're somewhat self documenting, take the containment hierarchy into account, encourage reusable chunks of code (Action objects), and allow actions to be easily removed, customized, or shared. Also, they make it easy to change the key to which an action is bound. Another advantage of Actions is that they have an enabled state which provides an easy way to disable the action without having to track which component it is attached to. "
- 08-20-2008, 02:50 PM #5
- By Sreejesh25 in forum New To JavaReplies: 11Last Post: 01-25-2011, 02:08 PM
- By Sreejesh25 in forum Advanced JavaReplies: 6Last Post: 03-05-2010, 08:12 PM
- By tom_k in forum New To JavaReplies: 7Last Post: 07-31-2008, 03:07 AM
- By gszauer in forum AWT / SwingReplies: 1Last Post: 12-15-2007, 11:42 PM
- By Bibendum in forum New To JavaReplies: 2Last Post: 11-02-2007, 03:51 AM