Urgent Help!

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2007
Posts: 108
Reputation: Majestics is an unknown quantity at this point 
Solved Threads: 7
Majestics Majestics is offline Offline
Junior Poster

Urgent Help!

 
0
  #1
Aug 20th, 2009
  1. import javax.swing.*;
  2.  
  3. import java.awt.*;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.awt.event.KeyEvent;
  7. import java.awt.Robot;
  8. import java.awt.Event;
  9. import java.awt.AWTException;
  10.  
  11.  
  12.  
  13.  
  14. public class keyboard implements ActionListener
  15. {
  16.  
  17. int i;
  18. String s[] = {"esc","F1","F2","F3","F4","F5",
  19. "F6","F7","F8","F9","F10","F11","F12",
  20. "psc","slk","pau","A","B","C","D","E",
  21. "F"};
  22. String g = "";
  23. Object b;
  24.  
  25. JMenuBar m = new JMenuBar();
  26.  
  27. JMenu m1 = new JMenu("File");
  28.  
  29. JMenu m2 = new JMenu("Keyboard");
  30. JMenu m3 = new JMenu("Setting");
  31. JMenu m4 = new JMenu("Help");
  32.  
  33. JMenuItem m11 = new JMenuItem("Exit");
  34. JMenuItem m21 = new JMenuItem("StandardKeyboard");
  35. JMenuItem m22 = new JMenuItem("ExtendedKeyboard");
  36. JMenuItem m26 = new JMenuItem("RegularLayout");
  37. JMenuItem m23 = new JMenuItem("101");
  38. JMenuItem m24 = new JMenuItem("102");
  39. JMenuItem m25 = new JMenuItem("106");
  40. JMenuItem m31 = new JMenuItem("Always On Top");
  41. JMenuItem m41 = new JMenuItem("About On-Screen Keyboard");
  42. JFrame f = new JFrame();
  43. JButton j[] = new JButton[(s.length)];
  44. Robot r;
  45.  
  46.  
  47.  
  48. keyboard()
  49. {
  50. m1.add(m11);
  51. m2.add(m21);
  52. m2.add(m22);
  53. m2.addSeparator();
  54. m2.add(m26);
  55. m2.addSeparator();
  56. m2.add(m23);
  57. m2.add(m24);
  58. m2.add(m25);
  59. m3.add(m31);
  60. m4.add(m41);
  61.  
  62. m.add(m1);
  63. m.add(m2);
  64. m.add(m3);
  65. m.add(m4);
  66.  
  67. m41.addActionListener(this);
  68.  
  69.  
  70.  
  71.  
  72. for(i=0;i<s.length;i++)
  73. {
  74. j[i] = new JButton(s[i]);
  75. j[i].setBackground(new Color(255,255,255));
  76. j[i].addActionListener(this);
  77.  
  78. }
  79.  
  80.  
  81. f.setLayout(new FlowLayout(FlowLayout.LEFT));
  82. f.setSize(630,200);
  83. Container c = f.getContentPane();
  84. c.setBackground(new Color(33,66,119));
  85.  
  86. f.setTitle("On-Screen Keyboard");
  87. f.setJMenuBar(m);
  88.  
  89. for(i=0;i<s.length;i++)
  90. c.add(j[i],JFrame.LEFT_ALIGNMENT);
  91.  
  92.  
  93. f.isMaximumSizeSet();
  94.  
  95. f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  96. f.setVisible(true);
  97. f.setFocusableWindowState(false);
  98.  
  99. try{
  100. Robot r = new Robot();
  101. r.delay(500);
  102. r.keyPress(KeyEvent.VK_7);
  103.  
  104. }
  105. catch (AWTException e) {
  106. e.printStackTrace();
  107. }
  108.  
  109. }
  110.  
  111.  
  112.  
  113. public static void main(String args[])
  114. {
  115. keyboard k = new keyboard();
  116.  
  117.  
  118. }
  119.  
  120. public void actionPerformed(ActionEvent e)
  121. {
  122. if(e.getSource() == m41)
  123. JOptionPane.showMessageDialog(null
  124. ,"Project By\nPirZada(20)\n"+
  125. "Salman Sayar(22)\n "+
  126. "Wajahat Kareem(16)","About On-Screen Keyboard",
  127. JOptionPane.INFORMATION_MESSAGE);
  128.  
  129. if(e.getSource() == j[16])
  130. {
  131.  
  132.  
  133.  
  134.  
  135. }
  136.  
  137. }
  138.  
  139.  
  140.  
  141.  
  142. }

Dear all user's please help , i am making on screen keyboard like XP one but i am confused , i want it to behave it like keyboard when i press button 'A' then it write that on the notepad or else , i tried robot class but it always give me an error so please kindly see my this project and help me what can i do to solve this problem
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 332
Reputation: quuba is on a distinguished road 
Solved Threads: 53
quuba quuba is offline Offline
Posting Whiz

Re: Urgent Help!

 
0
  #2
Aug 20th, 2009
change
try {
            // Robot
            r = new Robot();
            r.delay(500);
            r.keyPress(KeyEvent.VK_7);

        } catch (AWTException e) {
            e.printStackTrace();
        }
& try again
i tried robot class but it always give me an error
Error always is the source of information , carefully analyze it
Last edited by quuba; Aug 20th, 2009 at 5:03 pm. Reason: added
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 108
Reputation: Majestics is an unknown quantity at this point 
Solved Threads: 7
Majestics Majestics is offline Offline
Junior Poster

Re: Urgent Help!

 
0
  #3
Aug 20th, 2009
well sorry i forgot to take that code out of these , i just when i press any button it do in my keyboard through mouse then it work and that's what all i concerned.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 332
Reputation: quuba is on a distinguished road 
Solved Threads: 53
quuba quuba is offline Offline
Posting Whiz

Re: Urgent Help!

 
0
  #4
Aug 20th, 2009
Implement reciver
...then it write that on the notepad or else..
for example JTextField
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 108
Reputation: Majestics is an unknown quantity at this point 
Solved Threads: 7
Majestics Majestics is offline Offline
Junior Poster

Re: Urgent Help!

 
0
  #5
Aug 21st, 2009
JTextField only work inside java i want to send the events to outside environment.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,829
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Urgent Help!

 
0
  #6
Aug 21st, 2009
Robot will do fine for this problem, at least for part of this problem. Your main problem is this, I would imagine. Say you have three programs open: this Java program, Notepad, and a browser. At most, one of them will have the active focus. Or none of them could. So you have four possibilities for the key press:
  1. Focus is on Java program. Key press event goes to Java program.
  2. Focus is on Notepad program. Key press event goes to Notepad program.
  3. Focus is on browser program. Key press event goes to browser program.
  4. Focus is on none of the programs. Key press event goes to none of them.

You have a Java GUI with buttons, so in order for your actionPerformed to get called, the focus has to be on the Java program. You can easily use Robot to send a key stroke, but it'll go to the Java program, since that's what the focus is. Which you don't want. You want the key stroke to be sent to Notepad. So you need to somehow change that focus to Notepad. You can do that manually, by clicking Notepad after clicking the button on the Java program. So you could click the button on the Java program, then have a pause of three seconds or whatever, enough time to let you manually click Notepad active. Then the pause is over, so have Robot send that key press, which will end up on Notepad.

That's one way. or, presuming that Java knows where Notepad is on the screen, you can have Robot do the mouse press onto Notepad for you, then send the key press.

There's probably another way to set the focus that doesn't involve mouse clicking, or where you can actually specify the Notepad process number or something, but I don't know what it is. But changing focus from Java to Notepad and back is your main issue with this program, I would imagine.
Last edited by VernonDozier; Aug 21st, 2009 at 12:26 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Urgent Help!

 
0
  #7
Aug 21st, 2009
> Urgent Help!
This is neither descriptive nor accurate
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 108
Reputation: Majestics is an unknown quantity at this point 
Solved Threads: 7
Majestics Majestics is offline Offline
Junior Poster

Re: Urgent Help!

 
0
  #8
Aug 21st, 2009
All what you said is write but i want to do it automatically not manually clicking and there can any other active programe like microsoft word then how my programe send's the key .... I always post my problems here becz of great logical programer's and now no body can answer my this question....
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,829
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Urgent Help!

 
0
  #9
Aug 21st, 2009
Originally Posted by Majestics View Post
All what you said is write but i want to do it automatically not manually clicking and there can any other active programe like microsoft word then how my programe send's the key .... I always post my problems here becz of great logical programer's and now no body can answer my this question....
As I mentioned in my last post:

That's one way. or, presuming that Java knows where Notepad is on the screen, you can have Robot do the mouse press onto Notepad for you, then send the key press.

If you know the coordinate, you can have Robot click back and forth for you. That's a poor man's focus changer where it clicks, but you don't have to do the clicking yourself. But you'd have to know the location to click and tell the Java program. You might have to do a little bit of clicking in the beginning to test/find the window(s), but after you do, no more clicking.

As also mentioned in my last post too, there may well be a way to send it directly to Notepad if you know the process number or whatever, but I've never done it.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 207
Reputation: llemes4011 is an unknown quantity at this point 
Solved Threads: 13
llemes4011 llemes4011 is offline Offline
Posting Whiz in Training

Re: Urgent Help!

 
0
  #10
Aug 21st, 2009
If you're doing an on-screen keyboard, you will most likely want the keyboard to always be on top... im using it now, and it's state is 'inactive', yet it is still posting to the screen. This might be due to the fact that it can interact well with the Windows environment and has access to things Java does not. But I believe it is possible with java, but you might have to look into the JDesktop Project.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC