Re: How to intercept Ctrl key - eg Ctrl E being pressed on Java console program
Maybe I should explain what I want to do more fully. My Java command line
program waits for data to be received from a socket server.
But user needs to be able to stop program waiting - and I need to cleanup.
So Ctrl C works but I don't get a chance to cleanup and report successful
closedown to user.
My code so far is a bit like this:
BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));
String conline;
String responseLine;
for(;;)
{
// check not null stream and check user hasn't said quitread line from
user
if (((responseLine = bis.readLine()) != null) && (conline =
cin.readLine().equals("quit") == true)))
break;
System.out.println("Server said: " + responseLine);
}
Problem is that on the if line system is waiting for something to be typed
on command line. If nothing is typed it doesn't go onto display data from
server.
So I want it to continually display the data from server but have a way for
user to break out of for
By using this:
while ((responseLine = bis.readLine()) != null)
{
System.out.println("Server said: " + responseLine);
}
code worked but now way for user to break out of while loop.
Hopefully that explains what I need to achieve. Any help would be warmly
appreciated.
Angus
"Gordon Beaton" <n.o.t@for.email> wrote in message
news:455f19bd$0$8092$8404b019@news.wineasy.se...
On Fri, 17 Nov 2006 17:01:46 -0000, Angus wrote:
I am very new to Java. What is the normal way?
These have nothing to do with Java:
Ctrl-C: interrupt
Ctrl-D: EOF on stdin (Unix etc)
Ctrl-Z: EOF on stdin (Dos/Windows)
/gordon
--
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e