精华内容
下载资源
问答
  • KeyEvent

    2019-10-16 20:32:35
    ```java import java.awt.Color; import java.awt.Frame; import java.awt.TextField; import java.awt.event.KeyAdapter...import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt...
    
    ```java
    import java.awt.Color;
    import java.awt.Frame;
    import java.awt.TextField;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    
    public class MyKeyEvent {
    	public static void main(String[] args) {
    		new MyKeyFrame("键盘事件");
    	}
    }
    class MyKeyFrame extends Frame{
    	public MyKeyFrame(String s) {
    		// TODO Auto-generated constructor stub
    		super(s);
    		setVisible(true);
    		setBackground(Color.LIGHT_GRAY);
    		setBounds(500,500,500,500);
    		addWindowListener(new WindowAdapter() {
    			@Override
    			public void windowClosing(WindowEvent e) {
    				// TODO Auto-generated method stub
    				System.exit(0);
    			}
    		});
    		addKeyListener(new KeyAdapter() {
    			@Override
    			public void keyPressed(KeyEvent e) {
    				// TODO Auto-generated method stub
    				int KeyCode=e.getKeyCode();
    				if(KeyCode==KeyEvent.VK_UP) {
    					System.out.println("UP");
    				}
    				
    			}
    		});
    		
    	}
    }
    
    
    
    
    展开全文
  • keyevent

    2018-07-23 09:55:00
    按返回键弹出dialog判断是否要退出 连点两次才退出 转载于:https://www.cnblogs.com/znsongshu/p/9353129.html

    按返回键弹出dialog判断是否要退出

    连点两次才退出

     

    转载于:https://www.cnblogs.com/znsongshu/p/9353129.html

    展开全文
  • KeyEvent事件

    2019-12-14 14:21:20
    Java按键事件KeyEvent 按键事件可以利用键盘来控制和执行一些动作,或者从键盘上获取输入,只要按下,释放一个键或者在一个组件上敲击,就会触发按键事件。KeyEvent对象描述事件的特性(按下,放开,或者敲击一个键...

    Java按键事件KeyEvent


    按键事件可以利用键盘来控制和执行一些动作,或者从键盘上获取输入,只要按下,释放一个键或者在一个组件上敲击,就会触发按键事件。KeyEvent对象描述事件的特性(按下,放开,或者敲击一个键)和对应的值。java提供KeyListener接口处理按键事件。

     当按下一个键时会调用KeyPressed处理器,当松开一个键时会调用KeyReleased处理器,当输入一个统一编码时会调用KeyTyped处理器。如果这个键不是统一码(如功能键,修改键,动作键和控制键)
     每个按键事件有一个相关的按键字符和按键代码,分别由KeyEvent中的getKeyChar()和getKeyCode()方法返回
    
     getKeyChar():  char           返回这个事件中和键相关的字符
     getKeyCode():  int             返回这个事件中和键相关的整数键
    

    keyPressed(e: KeyEvent) 在源组件上按下一个键后被调用
    KeyReleased(e: KeyEvent) 在源组件上释放一个键后被调用
    KeyTyped(e: KeyEvent) 在源组件上按下一个键然后释放该键后被调用

    按键常量

    
    
    VK_HOME           Home键                          VK_CONTROL                  控制键
    VK_END            End键                             VK_SHIFT                       shift键
    VK_PGUP          page up键                       VK_BACK_SPACE             退格键
    VK_PGDN          page down键                   VK_CAPS_LOCK              大小写锁定键
    VK_UP              上箭头                            VK_NUM_LOCK                小键盘锁定键
    VK_DOWN         下箭头                            VK_ENTER                      回车键
    VK_LEFT           左箭头                            VK_UNDEFINED                未知键
    VK_RIGHT          右箭头                           VK_F1--VK_F12                F1 -- F12
    VK_ESCAPE       Esc键                              VK_0 --VK_9                    0 --- 9
    VK_TAB             Tab键                             VK_A --VK_Z                    A----Z
    

    getKeyCode() 返回定义在表中的值
    getKeyChar() 返回输入的字符

     1 import java.awt.*;
     2 import java.awt.event.*;
     3 import javax.swing.*;
     4  
     5 public class KeyEventDemo extends JFrame{
     6         private KeyboardPanel keyboardPanel = new KeyboardPanel();
     7        
     8         public KeyEventDemo(){
     9               add( keyboardPanel);
    10               
    11                keyboardPanel.setFocusable(true);
    12               
    13        }
    14        
    15         public static void main(String[] args){
    16               KeyEventDemo frame = new KeyEventDemo();
    17               frame.setTitle( "KeyEventDemo");
    18               frame.setSize(300,300);
    19               frame.setLocationRelativeTo( null);
    20               frame.setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE);
    21               frame.setVisible( true);
    22               
    23        }
    24        
    25         static class KeyboardPanel extends JPanel{
    26                private int x = 100;
    27                private int y = 100;
    28                private char KeyChar = 'A' ;
    29               
    30                public KeyboardPanel(){
    31                      addKeyListener( new KeyAdapter(){
    32                             public void keyPressed(KeyEvent e){
    33                                    switch(e.getKeyCode()){
    34                                    case KeyEvent.VK_DOWN: y += 10;break;
    35                                    case KeyEvent.VK_UP: y -= 10; break;
    36                                    case keyEvent.VK_LEFT: x -= 10; break;
    37                                    case KeyEvent.VK_RIGHT: x += 10; break;
    38                                    default: keyChar = e.getKeyChar();
    39                                   }
    40                                   
    41                                   repaint();
    42                            }
    43                      });
    44               }
    45               
    46                protected void paintComponent(Graphics g){
    47                       super.paintComponent(g);
    48                      
    49                      g.setFont( new Font("TimesRoman" ,Font.PLAIN,24));
    50                      g.drawString(String. valueOf(KeyChar), x, y);
    51               }
    52        }
    53 }
    
    
    
    展开全文
  • import java.awt.event.KeyEvent; //导入方法依赖的package包/类protected @Override boolean processKeyBinding(KeyStroke ks,KeyEvent e,int condition,boolean pressed) {if (Utilities.isMac()) {int mods = e....

    import java.awt.event.KeyEvent; //导入方法依赖的package包/类

    protected @Override boolean processKeyBinding(KeyStroke ks,

    KeyEvent e,

    int condition,

    boolean pressed) {

    if (Utilities.isMac()) {

    int mods = e.getModifiers();

    boolean isCtrl = (mods & KeyEvent.CTRL_MASK) != 0;

    boolean isAlt = (mods & KeyEvent.ALT_MASK) != 0;

    if (isAlt && (e instanceof MarkedKeyEvent)) {

    mods = mods & ~ KeyEvent.CTRL_MASK;

    mods = mods & ~ KeyEvent.CTRL_DOWN_MASK;

    mods |= KeyEvent.ALT_MASK;

    mods |= KeyEvent.ALT_DOWN_MASK;

    KeyEvent newEvent = new MarkedKeyEvent (

    (Component) e.getSource(), e.getID(),

    e.getWhen(), mods, e.getKeyCode(), e.getKeyChar(),

    e.getKeyLocation());

    KeyStroke newStroke = null;

    if( null != ks ) {

    newStroke = e.getID() == KeyEvent.KEY_TYPED ?

    KeyStroke.getKeyStroke (ks.getKeyChar(), mods) :

    KeyStroke.getKeyStroke (ks.getKeyCode(), mods,

    !ks.isOnKeyRelease());

    }

    boolean result = super.processKeyBinding (newStroke,

    newEvent, condition, pressed);

    if (newEvent.isConsumed()) {

    e.consume();

    }

    return result;

    } else if (!isAlt) {

    return super.processKeyBinding (ks, e, condition, pressed);

    } else {

    return false;

    }

    } else {

    return super.processKeyBinding (ks, e, condition, pressed);

    }

    }

    展开全文
  • KeyEvent對象是Java程序中用以描述按鍵事件的屬性和對應值,KeyListener接口用於處理按鍵事件。二、使用(轉載)当按下一个键时会调用KeyPressed处理器,当松开一个键时会调用KeyReleased处理器,当输入一个统一编码时...
  • android_KeyEvent

    2015-03-27 00:04:21
    介绍了androind开发中对于键盘监听类KeyEvent的成员变量定义以及API描述,并给出示例代码。
  • KeyEvent 键盘监听

    2021-03-31 16:22:39
    KeyEvent 键盘监听 学习笔记 import java.awt.Frame; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; public class Demo2 { public static void main(String[] args) { // TODO Auto-...
  • public void charPress(KeyEvent keyEvent) {float offset = keyEvent.isShiftDown() ? viewScale.smallPosOffset() : viewScale.largePosOffset();if (rightKeyboardCtrls) {switch (keyEvent.getKeyCode()) {case ...
  • android keyevent事件

    2011-12-22 15:26:42
    android keyevent事件分析
  • keyevent常用键列表

    2021-04-19 15:38:16
    adb shell input keyevent code详解 adb shell input keyevent 7 # for key ‘0’ adb shell input keyevent 8 # for key ‘1’ adb shell input keyevent 29 # for key ‘A’ adb shell input keyevent 54 # for ...
  • adb发送keyevent

    2018-02-13 15:52:46
    adb shell input keyevent 7 # for key '0' adb shell input keyevent 8 # for key '1' adb shell input keyevent 29 # for key 'A' adb shell input keyevent 54 # for key 'B'adb shell input text "A...
  • import java.awt.event.KeyEvent; //导入方法依赖的package包/类/** Overridden to allow standard keybinding processing of VK_TAB and* abort any pending drag operation on the vertical grid. */public void ...
  • 前言今天我们来聊一聊keyevent()接口,这个接口不仅能帮我们实现一些操作,比如删除输入框的内容、返回上一页等(下文会有详细的示例介绍)。并且合理地使用keyevent()接口,在一些情况下还会让我们脚本的兼容性更好。...
  • android keyEvent

    2015-07-29 11:11:00
    http://developer.android.com/reference/android/view/KeyEvent.html 转载于:https://www.cnblogs.com/melody-emma/p/4685398.html
  • 您的代码几乎没有问题:&...您最有可能使用java.awt.event.KeyEvent,它不适用于JavaFX事件.尝试使用javafx.scene.input.KeyEvent.下面显示了一个具体示例,您可以使用相同的方法将其转换为FXML:import javafx.applic...
  • /*** This method is used to turn keyboard key presses into actions*/private void toggle(KeyEvent ke, boolean pressed) {if ( ke.getKeyCode( ) == KeyEvent.VK_NUMPAD8 ) up.toggle( pressed ); //press keyp...
  • @Overridepublic void keyReleased(KeyEvent e) {switch (e.getKeyCode()) {case KeyEvent.VK_Q:Resources.useOQ = !Resources.useOQ;break;case KeyEvent.VK_RIGHT:Resources.numPasses++;Resources.numLayers = (R...
  • 满意答案你没有把KeyListener监听加到JFrame中,在MovingBall类中的this.add(mp); 语句后面加上一句this.addKeyListener(mp);...import java.awt.event.KeyEvent;import java.awt.event.KeyListener;import javax.s...
  • Android input keyevent

    千次阅读 2015-03-03 14:29:35
    adb shell input keyevnet 3 点击返回键操作 adb shell input keyevent 4 点击home键操作
  • @Overridepublic Screen respondToUserInput(final KeyEvent key, final MouseEvent mouse) {final int px = this.x;final int py = this.y;if (key != null) {switch (key.getKeyCode()) {case KeyEvent.VK_LEFT:ca...
  • KeyEvent对象描述事件的特性(按下,放开,或者敲击一个键)和对应的值。java提供KeyListener接口处理按键事件。当按下一个键时会调用KeyPressed处理器,当松开一个键时会调用KeyReleased处理器,当输入一个统一编码时...
  • @Overridepublic void keyReleased(KeyEvent e) {switch (e.getKeyCode()) {case KeyEvent.VK_Q:Resources.useOQ = !Resources.useOQ;break;case KeyEvent.VK_RIGHT:Resources.numPasses++;Resources.numLayers = (R...
  • Android按键Input KeyEvent

    千次阅读 2019-12-26 14:54:02
    使用android的Input输入系统,模拟...adb shell input keyevent 24 #音量- adb shell input keyevent 25 Instrumentation实现按键功能 代码实现,调用接口simulateKey() public static void simulateKey(final int K...
  • Android keyevent 整理

    2013-05-07 11:00:05
    Input keyevent method: input keyevent 82 menu input keyevent 3 home input keyevent 19 up input keyevent 20 down input keyevent 21 left input keyevent 22 right input keyevent 66 enter input ...
  • 记一个报错问题NameError:name 'keyevent' is not defined 环境: 手机:vivox9 安卓:7.1.2 adb版本:40 运行环境:airtestIDE 情况: keyevent('BACK')时报错,airtest其他操作正常 报错内容: ...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 6,860
精华内容 2,744
关键字:

keyevent