用java語(yǔ)言如何實(shí)現(xiàn)后臺(tái)鍵盤(pán)監(jiān)聽(tīng)?
this.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) { } @Override public void keyReleased(KeyEvent e) { } @Override public void keyPressed(KeyEvent e) { int keycode = e.getKeyCode(); switch (keycode) { case KeyEvent.VK_UP: { //do something break; } case KeyEvent.VK_DOWN: { //do something break; } case KeyEvent.VK_LEFT: { //do something break; } case KeyEvent.VK_RIGHT: { //do something break; } default: break; } } });