KeyListener

Hi ! I want to send an output saying "Done" when you push Alt + Y .Any idea how to make it happen ? ( I know how to send an ouput when only one key is pressed, but not when 2 keys are pressed at the same time ).Best wishes.Fares.
[271 byte] By [123_123a] at [2007-10-2 19:17:37]
# 1
In your listener, check the isAltDown method of the KeyEvent.
BaltimoreJohna at 2007-7-13 21:00:01 > top of Java-index,Security,Event Handling...
# 2

Hi !

I just figured that out while reading the API. But anyway thanks.

This is the code for anyone that has the same problem :

private class GUIKeyListener implements KeyListener {

public void keyTyped(KeyEvent e) {

// TODO Auto-generated method stub

}

public void keyPressed(KeyEvent e) {

// TODO Auto-generated method stub

if( e.isAltDown() ){

if( e.getKeyCode() == KeyEvent.VK_T ){

// action you want to perform

}

}

}

public void keyReleased(KeyEvent e) {

// TODO Auto-generated method stub

}

}

123_123a at 2007-7-13 21:00:01 > top of Java-index,Security,Event Handling...
# 3

I have been having a problem with my code. I think its all ok, but it doesnt always work. If I run the program enough it eventually works that one time.

Here's some of the code:

public void keyTyped(KeyEvent e)

{

int key=e.getKeyCode();

char keychar=e.getKeyChar();

System.out.println("Key Code:" + key);

System.out.println("Key char:" + keychar);

//String keystr=KeyEvent.getKeyText(0);

//System.out.println("keystr is " + keystr);

//System.out.println(key);

if(ready)

{

if(keychar=='a')

{

System.out.println("LEFT");

if(xcoord>0)

{

xcoord--;

ready=Character.moveAnimation(1);

}

}

else if(keychar=='d')

{

System.out.println("RIGHT");

if(xcoord<15)

{

xcoord++;

ready=Character.moveAnimation(2);

}

}

else if(keychar=='w')

{

System.out.println("UP");

if(ycoord>1)

{

ycoord--;

ready=Character.moveAnimation(3);

}

}

else if(keychar=='s')

{

System.out.println("DOWN");

if(ycoord<8)

{

ycoord++;

ready=Character.moveAnimation(4);

}

}

System.out.println(ready);

}//End if ready

}

I want to use the arrow keys, but they are never read even when the rest of the keyboard works.

If you need more code to find the program please ask me!

I've been trying to find the answer to the problem for a while.

Mag9102a at 2007-7-13 21:00:01 > top of Java-index,Security,Event Handling...
# 4
Mag, why didn't you create your own post?
BaltimoreJohna at 2007-7-13 21:00:01 > top of Java-index,Security,Event Handling...
# 5
sorry, I thought since he had code posted to help i would see if he knew what might have been wrong. If you know how to delete a post you can.
Mag9102a at 2007-7-13 21:00:01 > top of Java-index,Security,Event Handling...
# 6

Hi all

can anybody pls give an explanation to this

If suppose i have pressed a key( For eg: Enter) then how the application knows that the key pressed is Enter key.

From my understanding Basically the eventq will contain the type of events, its corresponding keycodes & keychar. it is fiiling one strucure from the native implementation and sending those structure to java file.

I want to know the functional flow of event handling from the moment it fills the eventq to the executing section.

If a component contains "OK" and "CANCEL" button. with "OK" having the focus. and if i press "ENTER" how this is executing

currently i am using the pbp1.0 code with microwindows.

Can Anyone can give inputs on this. Thanks in advance

Sivaprasada at 2007-7-13 21:00:01 > top of Java-index,Security,Event Handling...