1

I'm currently using JLine (http://jline.sourceforge.net/) to read characters from the console in Java one at a time.

Terminal terminal = TerminalFactory.getFlavor(TerminalFactory.Flavor.WINDOWS);
terminal.init();
terminal.setEchoEnabled(false);

int i;
InputStream in = terminal.wrapInIfNeeded(System.in);

i = in.read();

How can I detect if the Ctrl or Alt keys are pressed when I called in.read();? I can't figure out from either the javadocs or any other source how to read if the Ctrl or Alt key is pressed.

Keshan Nageswaran
  • 8,060
  • 3
  • 28
  • 45
Femi
  • 64,273
  • 8
  • 118
  • 148

1 Answers1

1

You need to get keyboard scan codes which can be done using a native library. See: How can I get the keyboard scan code in java? Specifically: https://github.com/kwhat/jnativehook

AlexC
  • 1,395
  • 14
  • 26