The Artima Developer Community
Sponsored Link

Java Answers Forum
KeyTyped Event

3 replies on 1 page. Most recent reply: May 5, 2005 4:23 AM by Matthias Neumair

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

KeyTyped Event Posted: Apr 20, 2005 2:14 AM
Reply to this message Reply
Advertisement
I'm using a JTextfield wich should react to the VK_DOWN key in a keytyped event.

KeyPressed and KeyReleased work perfect, but KeyTyped i a mess:
If I press a alphanumeric character (A, B, C, ..., 1, 2, 3 ...) the result of getKeyCode() is allways 0
Even better: There is no KeyTyped event generated at all by I press any non-alphanumeric key (ex: no event for ALT, CTRL, VK_DOWN, F1 ...)

I don't know if a standard textfield has the same errors.

I'm using Java 1.5.0_02
All this worked once (I think in 1.4).

Does anyone know if there is a way to fix this?


Sean Downes

Posts: 1
Nickname: thejuggler
Registered: Feb, 2005

Re: KeyTyped Event Posted: May 3, 2005 3:53 AM
Reply to this message Reply
unsure if its the best method, but it worked, I used the following code to determine if the 'Ctrl', 'Shift' or 'Alt'
key were pressed

// Shift, Ctrl or Alt ???
if(e.getKeyText(e.getKeyCode()).equalsIgnoreCase("Alt")
|| e.getKeyText(e.getKeyCode()).equalsIgnoreCase("Shift")
||e.getKeyText(e.getKeyCode()).equalsIgnoreCase("Ctrl"))
{
return;
}
//ALSO // used the following code to determine whether
// left, right, up and down arrows, Function keys, Home, End etc. keys were pressed
if( e.isActionKey() )
{
return;
}

Amol Brid

Posts: 43
Nickname: amolbrid
Registered: Feb, 2004

Re: KeyTyped Event Posted: May 4, 2005 7:49 AM
Reply to this message Reply
Hi Matthias,

There is no problem with the TextField.

The keyTyped event is high level event and is generated only for the Unicode characters. So if you want to work with Unicode characters then you should write the code in this function. You can also get the status of ALT, CRTL and SHIFT key in this. But no keycode.

keyPressed and keyReleased events are low level events and are generated for the all the keys present on the keyboard. So no matter which key you press on keyboard, keyPressed and keyReleased event will be generated(except for TAB). If you are working with funtion keys then use these function.


Get back if you have any problem.

Regards,
Amol Brid.

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: KeyTyped Event Posted: May 5, 2005 4:23 AM
Reply to this message Reply
The event WAS launched in Java 1.4 for the arrow keys (that's what I used it for).

In the meantime I changed my program to work with keypressed.

Thanks anyway

Flat View: This topic has 3 replies on 1 page
Topic: NetBeans - compile parameters Previous Topic   Next Topic Topic: How to write an exe file for a java project?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use