explicitClick to confirm you are 18+

some keys

ewingSep 6, 2015, 3:02:49 PM
thumb_upthumb_downmore_vert

javaprog

the following javaprogram reads any keypress without Enter and its output is the key and its asciivalue in brackets. as precaution jcurses has to be properly set up. ctrl-c or '#' ends the program. only the input is coded, a simple System.out.println serves as output. as processing of the values nearly anything can be imagined.

import jcurses.system.InputChar;
import jcurses.system.Toolkit;

public class readchar3 {
public static void main (String[] args)
{
String st;
char ch;
int i;
st = "";
ch = ' ';
i = 0;
while (true)
{
InputChar c = Toolkit.readCharacter();
ch = c.getCharacter();
i = (int) ch;
System.out.print ("you typed " + ch + "(" + i + ")\n\r");
// break on '#'
if (ch == '#') break;
}
System.out.println ("Programm wird beendet. Verarbeitung kann beginnen.");
}
}