Java-check if control key is being pressed

后端 未结 4 1351
孤街浪徒
孤街浪徒 2020-12-21 00:47

I have a Java function in which I want to test if the control key is being held down. How can I do that?

Edit: I am using swing for gui.

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-21 01:22

    It depends on several things.

    If you're running the Java program as a console program (text based) you have to test for approriate bits in the received chatracter.

    Otherwise, you should look at InputEvents for the appropriate GUI classes, eg, http://docs.oracle.com/javase/6/docs/api/java/awt/event/InputEvent.html.

    Have a look at this tutorial: http://docs.oracle.com/javase/tutorial/uiswing/events/keylistener.html

提交回复
热议问题