From: Henrik J. <hen...@ho...> - 2003-08-11 16:20:49
|
I've tried to use irxevent to send keyevents to a java application. The problem is that it only works as long as the java window is focused. This is a piece of code that I've written to test this: import java.awt.*; import java.awt.event.*; public class Test { public static void main( String[] args ) { Win w= new Win(); w.setVisible( true ); } } class Win extends Frame implements KeyListener { Label text; public Win() { super( "test" ); this.addKeyListener( this ); this.setUndecorated( true ); this.setBounds( 0, 0, 200, 200 ); text= new Label( "" ); text.setAlignment( 1 ); add( text ); } public void keyTyped( KeyEvent ke ) {} public void keyPressed( KeyEvent ke ) { if( ke.getKeyCode() == KeyEvent.VK_UP ) text.setText( "up" ); else if( ke.getKeyCode() == KeyEvent.VK_DOWN ) text.setText( "down" ); else if( ke.getKeyCode() == KeyEvent.VK_LEFT ) text.setText( "left" ); else if( ke.getKeyCode() == KeyEvent.VK_RIGHT ) text.setText( "right" ); else if( ke.getKeyCode() == KeyEvent.VK_ESCAPE ) System.exit( 0 ); } public void keyReleased( KeyEvent ke ) {} } Does anyone else know if this should work? And yes, I know about jlirc, but it feels a little unnecessary as irxevent should be able to do the same thing... Regards Henrik Johansson |