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

Recommended Answers

All 4 Replies

Member Avatar for iamthwee

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?

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

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.