我也是刚开始自学这个问题我查过。通过InputEvent类可以接收输入的按键,在InputEvent类里定义了一些掩码。他们是int型的整数。例如:鼠标左健是BUTTON1_MASK,鼠标右键是BUTTON2_MASK,还有CTRL_MASK,ALT_MASK,SHIFT_MASK.比如判断按下CTRL+鼠标左键: InputEvent.CTRL_MASK+InputEvent.BUTTON1_MASK;
调试欢乐多
磨办法啊。绕路走吧。曲线救Java
具体问题具体分析哦,
用console?
不可能吧, cttl + z是返回啊,
程序不可能运行了
回车提交和回显好像系统提供的东西。磨办法啊。
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.PrintStream;
import java.util.Timer;
import java.util.TimerTask;/**
* This class is TODO class.
* @author wenzhou
* @version $Id$
*/public class TestInput
{
public StringBuffer cacheString = new StringBuffer();
public boolean blockOutput = false; public TestInput() throws Exception
{
PrintStream orgOut = System.out;
//下边一段模拟输出
final Timer timer = new Timer();
TimerTask task = new TimerTask() {
int i = 1;
public void run()
{
println("Test output; " + (i++));
if(i > 1000)
{
timer.cancel();
}
}
};
timer.schedule(task ,1000L,1000L);//下边一段想办法修改输入,未果
//下边这两句是打算把系统的BufferedInputStream去掉。以为就不缓冲了。结果
//还是不行。
//FileInputStream fdIn = new FileInputStream(FileDescriptor.in);
//System.setIn(fdIn);
while(true)
{
FileDescriptor.in.sync();
if(System.in.available() != 0)
{
char c = (char) System.in.read();
//按S键暂停打印
if(c == 's')
{
setBlock(true);
}
//按Q键恢复打印
else if(c == 'q')
{
setBlock(false);
}
}
}
}
//搞个缓冲把输出存起来
public void setBlock(boolean block)
{
blockOutput = block;
if(!blockOutput)
{
System.out.println(cacheString);
cacheString = new StringBuffer();
}
}
public void println(String s)
{
if(blockOutput)
{
cacheString.append(s);
cacheString.append("\n");
}
else
{
System.out.println(s);
}
}
public static void main(String[] args) throws Exception
{
new TestInput();
}
}
String erase = "\b \b";
System.out.print(erase);
System.out.print(erase);