About whether System.setIn (), can seize keyboard control.

  1. when I saw this, I wondered blindly whether I would use this sentence to invalidate keyboard input. All the input content is from a file set by myself.
  2. it"s OK to write a simple java file, but what if it"s an application?
  3. Can
  4. get keyboard control wherever jvm is running?
Sep.11,2021

System.setIn just changes the standard input device of the current application. You can use the following example:

public class NewSystemIn {

    public static void main(String ...args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextLine()) {
            System.out.println(scanner.nextLine());
        }
    }
}

when Program 1 outputs the contents of a custom input device, Program 2 still behaves normally (can read keyboard input).

Keyboard won't be implemented so easily.

Menu