Henrik,
Look at the documentation for KeyEvent in the standard Java Docs. There
is a method KeyEvent#getKeyCode() that will return the key code to you.
You can then compare this code with the constants defined in the same
class (KeyEvent#VK_A).
-mike
On Tue, 2003-12-16 at 07:20, Henrik Allendorf wrote:
> Dear all,
>
> I would like to write my own KeyBehavior, but I have problems to identify the
> pressed key.
> Can someone help me? E.g. when I press the key "a", I would like to do something.
>
> Here's my code:
>
> public class NavBehavior extends Behavior{
>
> private TransformGroup viewTG;
> //NavigationCalculator
> private NavCalculator navCalculator;
>
> private Transform3D t3d = new Transform3D();
>
> //debugging switch
> private final static boolean deb=true;
>
>
> //Konstruktor
> public NavBehavior(TransformGroup viewPlatformTG, NavCalculator navCalc){
> viewTG = viewPlatformTG;
> navCalculator = navCalc;
> }
>
>
> public void initialize() {
> this.wakeupOn(new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED));
> }
>
> public void processStimulus(Enumeration criteria) {
>
> WakeupCriterion wakeup;
> AWTEvent[] event;
> int eventId;
>
> while (criteria.hasMoreElements()){
> wakeup = (WakeupCriterion) criteria.nextElement();
> if (wakeup instanceof WakeupOnAWTEvent){
> event = ((WakeupOnAWTEvent) wakeup).getAWTEvent();
> for (int i=0; i<event.length; i++){
> eventId = event[i].getID();
> if(eventId == KeyEvent.KEY_PRESSED){
> String test = event[i].toString();
> Debug.out(deb, "id: "+test);
> Transform3D tempT3D = navCalculator.makeEyePosition(0.0d, 0.0d);
> viewTG.setTransform(tempT3D);
> }
> }
> }
> }
> this.wakeupOn(new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED));
>
> }
>
> }
>
> Henrik
>
>
> -------------------------------------------------
> This mail sent through IMP: http://www.geoinform.fh-mainz.de/webmail
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff JAVA3D-INTEREST". For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".