Make java act like a key is pressed.

is there any way to key java to emulate a key being pressed. i need it control a media player by using the media players shortcut keys. so when an event happens it will send a pre determined key to windows?
[213 byte] By [boozelclarka] at [2007-11-27 3:59:49]
# 1
Same way you would do it with a mouse click clicking the button. If your frame has focus, and you press a key, your listener will catch it, and then act accordingly.
kdajania at 2007-7-12 9:04:23 > top of Java-index,Security,Cryptography...
# 2
thanks but what i need is that when a button is pressed it does the same thing as if a certain key is pressed so that my media player thinks the key is being pressed. any help?
boozelclarka at 2007-7-12 9:04:23 > top of Java-index,Security,Cryptography...
# 3

> ...what i need is that when a button is

> pressed it does the same thing as if a certain key is

> pressed so that my media player

Do you mean something like Windows Media

Player(a), as opposed to the JMF(b)?

>..thinks the key is

> being pressed.

a) For native applications, the java.awt.Robot

class might help here.

It has methods to move the mouse, make

mouseclicks and send key events.

For this method to work, the location of the media

player needs to be known to the Robot (so it can

click in the right places to make it active and give

it keyboard focus, for example).

b) For Java based apps., like JMF, the strategy

outlined by the first respondent is the best.

Access the buttons and such direct through Java.

AndrewThompson64a at 2007-7-12 9:04:23 > top of Java-index,Security,Cryptography...
# 4
thanks
boozelclarka at 2007-7-12 9:04:23 > top of Java-index,Security,Cryptography...