[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] læse et enkelt tastetryk fra tasteturet i java



Torsdag den 14. juli 2005 21:30 skrev Siemen Baader:
> Hej!
>
> Jeg er ved at skrive et lille tekstbaseret program i java, som skal
> hjælpe med at slå op i en database over kemikalier. Da kemikalier har
> frygtelig lange navne vil jeg gerne lade programmet gætte matchende
> kemikalier, mens brugeren indtaster et navn. Jeg har altså brug for en
> metode, der kan læse et enkelt bogstav fra tastaturet, så jeg
> efterfølgende kan slå op i datasen og vise de mulige fund - lidt på
> samme måde som tab-completion i bash, bare on-the-fly.

Hmm. Nu er jeg absolut ingen java hacker. Men, hey, vi har jo kun det skæg vi 
selv sidder på...

prøv følgende program

import java.io.*;

class input {

    public static void main( String[] args ) {
	try{
	    int c = System.in.read();
	    System.out.println( "Your entered: " + c );
	} catch ( IOException ioe ) {
	    ioe.printStackTrace();
	}
    } //end main()
    
}


Kør det med 
$ stty cbreak; java input; stty -cbreak

Du kan putte det i et script. Så har du unbuffered input, og ligemeget hvordan 
du afslutter input programmet, så bliver tty'en sat tilbage til -cbreak (som 
er default).

Godt nok?

Mads

-- 
Mads Bondo Dydensborg


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 22:44 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *