码迷,mamicode.com
首页 > 其他好文 > 详细

e645. 处理键盘事件

时间:2018-09-02 23:59:12      阅读:298      评论:0      收藏:0      [点我收藏+]

标签:dap   ==   related   body   key   present   proc   nic   event   

You can get the key that was pressed either as a key character (which is a Unicode character) or as a key code (a special value representing a particular key on the keyboard).

    
component.addKeyListener(new MyKeyListener());
    
    public class MyKeyListener extends KeyAdapter {
        public void keyPressed(KeyEvent evt) {
            // Check for key characters.
            if (evt.getKeyChar() == ‘a‘) {
                process(evt.getKeyChar());
            }
    
            // Check for key codes.
            if (evt.getKeyCode() == KeyEvent.VK_HOME) {
                process(evt.getKeyCode());
            }
        }
    }

 

Related Examples

e645. 处理键盘事件

标签:dap   ==   related   body   key   present   proc   nic   event   

原文地址:https://www.cnblogs.com/borter/p/9575412.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!