Answer: <P>You can do it without using key event, by creating an artificial key event using java.awt.Robot class to generate a "simple caracter" key press (for instance KeyEvent.VK_A). <BR>Sample Source Code -- May not be accurate but the concept is as follows. </P><P><EM><FONT style="BACKGROUND-COLOR: #ffcc00">import java.awt.*;<BR>import java.awt.event.*;</FONT></EM></P><P><EM><FONT style="BACKGROUND-COLOR: #ffcc00">public class Test {</FONT></EM></P><P><EM><FONT style="BACKGROUND-COLOR: #ffcc00"> public static void main(String[] args) throws AWTException {<BR> <BR> // create AWT component<BR> Frame f = new Frame();<BR> // handle component's keyPressed event<BR> f.addKeyListener(new KeyAdapter() { public void <BR>keyPressed(KeyEvent ev) {System.out.println<BR> <BR> (Character.isUpperCase( ev.getKeyChar()) ? "Caps Lock <BR>ON" :"Caps Lock OFF");} <BR> });<BR> // make component visible (otherwise the Robot won't <BR>work)<BR> f.show();<BR> // create Robot<BR> Robot robot = new Robot();<BR> // generate simple caracter key press<BR> robot.keyPress(KeyEvent.VK_A); <BR> <BR> }</FONT></EM></P><P><EM><FONT style="BACKGROUND-COLOR: #ffcc00">}</FONT></EM></P>
Tags:Interview Questions, J2EE, Java,
Please submit your Interview Answer for the above Question via replying to this post. Thank you for visiting to our blog, Have a Good Day!.
Sponsor Advertisement
Real Estate Management System Software
Real Estate Management Software is an advanced end-to-end Real Estate Office Management System that enables Real Estate Agencies to manage more effectively, search prorty details, keep property owner data etc. Web-based tracking and accounting solution ideal for commercial, residential housing....
No comments:
Post a Comment