In Java, how to make shortcuts similar to Emacs?

I want to know how to add shortcuts like Emacs in my Java application. For example C-x C-fand C-x b.

Thank.

+3
source share
2 answers

Java provides a means for identifying modifier keys. By modifier keys, I mean

  • Alt - e.isAltDown ();
  • Ctrl - e.isControlDown ();
  • Shift - e.isShiftDown ()

These achachas connect to other keys on the regular keyboard from the keyboard to determine if a combination has been pressed.

if( (e.isControlDown() && e.getKeyCode() == KeyEvent.VK_X) )
{

}

e.getModifiers () can be used to identify the modifier, as well as the click of a mouse. This returns a bitmask.

See here. http://www.leepoint.net/notes-java/GUI-lowlevel/keyboard/keyboard.html

Ctrl. , .

   JTextField sampleTxtFld= new JTextField();

   sampleTxtFld.addKeyListener(new KeyAdapter() {


          public void keyPressed(KeyEvent e) 
         {
              if((e.isControlDown() && e.getKeyCode() == KeyEvent.VK_X)
              {
                    //identifies whether Ctrl + X has been pressed
                    // do some action here
              }
         }

        public void keyReleased(KeyEvent e) 
        {
              //some key released code here
        }
         public void keyTyped(KeyEvent e) {
         }


   });
0

, EMACS - . KeyStrokes Swing, . , . . - .

0

All Articles