How do I check if the user is pressing a key?

前端 未结 3 1615
盖世英雄少女心
盖世英雄少女心 2020-11-22 16:30

In java I have a program that needs to check continuously if a user is pressing a key. So In psuedocode, somthing like

if (isPressing(\"w\"))
{
 //do somthin         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 16:58

    You have to implement KeyListener,take a look here: http://docs.oracle.com/javase/7/docs/api/java/awt/event/KeyListener.html

    More details on how to use it: http://docs.oracle.com/javase/tutorial/uiswing/events/keylistener.html

提交回复
热议问题