Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
806 views
in Technique[技术] by (71.8m points)

swing - Java-check if control key is being pressed

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

use the "isControlDown()" boolean:

public void keyPressed (KeyEvent e)
{
     System.out.println(e.isControlDown());
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
...