How to make a virtual keyboard in Java for other programs?

I want to make something like a virtual keyboard for ultrabooks with a touch screen in Java. For example, I want to type my virtual keyboard in Microsoft Word.

What I have done so far is to use JButtonto represent keys and use the class Robotto simulate computer input.

The problem is that when I click the button JButton, it focuses JButton, so the class Robotdirects the input in JButtoninstead of the program I want to enter, for example Microsoft Word.

My code looks like this for button A

int KeyValue = KeyEvent.VK_A;
Robot robot ...

JButtton.addMouseListener(new MouseListener(){
    ...
    public void mousePressed(MouseEvent e){
        robot.keyPress(KeyValue);
    }
    public void mouseReleased(MouseEvent e){
        robot.keyRelease(KeyValue);
    }
    ...
}
...

, . KeyListener JButton, "A" , ​​ JButton .

JButton.setFocusable(false), ...

, , Java , .

, : , ? JButtons, ?

+4
1

JFrame setFocusableWindowState(false);.

+2

Source: https://habr.com/ru/post/1599703/


All Articles