954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Keyboard Input

Hi

Just wondering if anyone can help. I have a gui and have assigned a KeyListener to it, It recognizes keyboard input for standard keys but doesnt seem to recognise special keys like shift and function keys? Is there some special way to be able to get it to react to function keys. I need to be able to store when a shift key is pressed or when 'F2' is pressed. To give you an idea im doing a replica of MineSweeper and need it to restart the game if F2 is pressed and need to be able to get the shift and return key for the cheat to work. Any help woul dbe great.

Thanks in Advance

Black Knight
Light Poster
25 posts since Mar 2005
Reputation Points: 10
Solved Threads: 0
 

Hi

Just wondering if anyone can help. I have a gui and have assigned a KeyListener to it, It recognizes keyboard input for standard keys but doesnt seem to recognise special keys like shift and function keys? Is there some special way to be able to get it to react to function keys. I need to be able to store when a shift key is pressed or when 'F2' is pressed. To give you an idea im doing a replica of MineSweeper and need it to restart the game if F2 is pressed and need to be able to get the shift and return key for the cheat to work. Any help woul dbe great.

Thanks in Advance

Possibly this, although I haven't had time to read over it. http://java.sun.com/docs/books/tutorial/uiswing/events/keylistener.html

If worse comes to the worst I guess you could use some other keys or create your own button in the GUI?

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

the KeyEvent would state any modifiers on the key. a modifier would be something like a shift or control key.

Phaelax
Practically a Posting Shark
858 posts since Mar 2004
Reputation Points: 92
Solved Threads: 51
 

unfortunatly its not tryin gto pick up the shift as a modifyer, it needs to recognize when just the shift key is pressed. the cheat code is like, 'press x,y,z,z,y,left shift, return' and they need to be pressed seperatly. when the keys get pressed the keycode gets put into an array and if that array matchs the cheat array then the cheat is active.

Black Knight
Light Poster
25 posts since Mar 2005
Reputation Points: 10
Solved Threads: 0
 

Got it!!, It doesnt recognize things like Function keys and shift etc in teh KeyTyped method, it only sees those keys seperatly in the KeyPressed or KeyReleased Methods.

Black Knight
Light Poster
25 posts since Mar 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You